Scilab Function
eng - fr


import_data_to_file - import xml sections from data files

Library

Calling Sequence

import_data_to_file(rep_xml,flag,rep_data)

Parameters

File content


//Fonction qui importe des données à partir des fichiers
//
//dans la base de fichers xml
//
//import_data_to_file
// flag un vecteur de chaîne de caractères
// 'param'
// 'sdesc'
// 'see_also'
// 'authors'
// 'ex'
// 'desc'
// 'used_func'
// 'biblio'
// 'SPECIALDESC'
// 'all'
// 'call_seq'
// rep_xml :  répertoire de stockage des fichiers 
//            xml (ex:rep_xml=xml_path)
// rep_data : répertoire de stockage des fichiers 
//            de données
//Modif : passez le flag <LaTeX> en <LaTeX force>
//pour mettre votre fichier latex à jour
function import_data_to_file(rep_xml,flag,rep_data)
 
 //Verifie cohérence des  paramètres 
 [lsh,rsh]=argn();
 if rsh<3 then 
  rep_data=man_path
  else
   rep_data=pathconvert(rep_data,%t) 
 end;
 
 if flag=='all' then
  flag=['param';'sdesc';'see_also';
        'authors';'ex';'desc';'used_func';
        'biblio';'SPECIALDESC';'call_seq']
 end
 
 //def des noms de fichiers de donées
 file_param='MODNUM_data_param';
 file_sdesc='MODNUM_data_sdesc';
 file_see_also='MODNUM_data_see_also';
 file_authors='MODNUM_data_authors';
 file_ex='MODNUM_data_ex';
 file_desc='MODNUM_data_desc';
 file_call_seq='MODNUM_data_call_seq';
 file_used_func='MODNUM_data_used_func';
 file_biblio='MODNUM_data_biblio';
 file_spec_desc='MODNUM_SPECIALDESC';

 for z=1:size(flag,1)
   flagn=flag(z);

   /////////
   //'param'
   /////////
   if flagn=='param' then
    if fileinfo(rep_data+file_param)<>[] then
      printf("Import xml parameters...\n");
      tt=mgetl(rep_data+file_param);
      i=1;
      k=0;
      while i<size(tt,1)
        if strindex(tt(i),'<FILE ')<>[] then
          a=i;
          namef=strsubst(tt(i),'<FILE ',"");
          namef=strsubst(namef,'>',"");
          i=i+1;
        elseif strindex(tt(i),'</FILE ')<>[] then
          b=i;
          len_param=evstr(b-a-1);
          if len_param>0 then
            tt_temp=tt(a+1:b-1);
            //mon code
            j=0;
            nb_indent=0;
            //Trouve la profondeur max d'indentation
            for l=1:size(tt_temp,1)
              if strindex(tt_temp(l),'<INDENT>')<>[] then
                j=j+1;
              elseif strindex(tt_temp(l),'</INDENT>')<>[] then 
                j=j-1;
              end
              if j>nb_indent then nb_indent=j; end
            end
            //initialise la liste
            txt_list=list();
            for l=1:nb_indent
              txt_list(l)=list();
              txt_list(l)(1)=[];
              txt_list(l)(2)=[];
            end
            //Remplissage de la liste
            j=0;
            e=0;
            for l=1:size(tt_temp,1)
              if strindex(tt_temp(l),'<INDENT>')<>[] then
                j=j+1;
              elseif strindex(tt_temp(l),'TITLE=')<>[] then
                e=e+1; 
                txt_list(j)(1)=[txt_list(j)(1);e];
                title_tmp=strsubst(tt_temp(l),'TITLE=',''); 
              elseif strindex(tt_temp(l),'DESC=')<>[] then
                desc_tmp=strsubst(tt_temp(l),'DESC=','');
                txt_list(j)(2)=[txt_list(j)(2);title_tmp,desc_tmp]; 
              elseif strindex(tt_temp(l),'</INDENT>')<>[] then 
                j=j-1;
              end
            end
          elseif len_param==0 then
             txt_list=list();
          end
          if fileinfo(rep_xml+namef)<>[] then
             printf("Update %s... ",namef);
             new_tt=put_xml_param3(txt_list,rep_xml+namef);
             mputl(new_tt,rep_xml+namef);
             printf("Done\n");
             k=k+1;
          end
          a=0;b=0;
          i=i+1
        else
          i=i+1
        end
      end
      printf("Processed %d files\n",k);
    else
      printf("file %s not found\n",file_param);
    end

   //////////
   //'sdesc'
   /////////
   elseif flagn=='sdesc'
    if fileinfo(rep_data+file_sdesc)<>[] then
      printf("Import xml short descriptions...\n");
      tt=mgetl(rep_data+file_sdesc);
      i=1;
      k=0;
      while i<size(tt,1)
        if strindex(tt(i),'<FILE ')<>[] then
          namef=strsubst(tt(i),'<FILE ',"");
          namef=strsubst(namef,'>',"");
          i=i+1;
          txt=tt(i);
          if strindex(txt,'</FILE')<>[] then
            txt=""
          end
          if fileinfo(rep_xml+namef)<>[] then
            printf("Update %s... ",namef);
            new_tt=put_xml_sdesc(txt,rep_xml+namef);
            mputl(new_tt,rep_xml+namef);
            printf("Done\n");
            k=k+1;
          end
        else
          i=i+1
        end
      end    
      printf("Processed %d files\n",k);
    else
      printf("file %s not found\n",file_sdesc);
    end
    
   ///////////
   //see_also
   ///////////
   elseif flagn=='see_also'
    if fileinfo(rep_data+file_see_also)<>[] then
      printf("Import xml see_also...\n");
      tt=mgetl(rep_data+file_see_also);
      i=1;
      k=0;
      a=0;
      b=0;
      while i<size(tt,1)
        if strindex(tt(i),'<FILE ')<>[] then
          a=i;
          namef=strsubst(tt(i),'<FILE ',"");
          namef=strsubst(namef,'>',"");
          i=i+1
        elseif strindex(tt(i),'</FILE ')<>[] then
          b=i;
          num_see_also=evstr(b-a-1);
          if num_see_also>=0 then
            if num_see_also==0 then
             txt=""
            else
             txt=tt(i-num_see_also:i-1)
            end
            if fileinfo(rep_xml+namef)<>[] then
              printf("Update %s... ",namef);
              new_tt=put_xml_see_also(txt,rep_xml+namef);
              mputl(new_tt,rep_xml+namef);
              printf("Done\n");
              k=k+1;
            end
          end
          a=0;b=0;
          i=i+1
        else
         i=i+1
        end 
      end
      printf("Processed %d files\n",k);
    else
      printf("file %s not found\n",file_see_also);
    end
    
   ///////////
   //'authors'
   ///////////
   elseif flagn=='authors' then
    if fileinfo(rep_data+file_authors)<>[] then
      printf("Import xml authors...\n");
      tt=mgetl(rep_data+file_authors);
      i=1;
      k=0;
      while i<size(tt,1)
        if strindex(tt(i),'<FILE ')<>[] then
          namef=strsubst(tt(i),'<FILE ',"");
          namef=strsubst(namef,'>',"");
          i=i+1;
          num_authors=evstr(tt(i));
          if num_authors<>0 then
            txt=emptystr(num_authors,2);
            txt(:,1)=tt(i+1:i+num_authors);
            txt(:,2)=tt(i+1+num_authors:i+2*num_authors);
            i=i+1+2*num_authors;
            if fileinfo(rep_xml+namef)<>[] then
              printf("Update %s... ",namef);
              new_tt=put_xml_authors(txt,rep_xml+namef);
              mputl(new_tt,rep_xml+namef);
              printf("Done\n");
              k=k+1;
            end
          end
        else
          i=i+1
        end
      end
      printf("Processed %d files\n",k);
    else
      printf("file %s not found\n",file_authors);
    end
    
   ///////
   //'ex'
   ///////
   elseif flagn=='ex' then
    if fileinfo(rep_data+file_ex)<>[] then
      printf("Import xml & latex examples...\n");
      tt=mgetl(rep_data+file_ex);
      i=1;
      k=0;
      while i<size(tt,1)
        if strindex(tt(i),'<FILE ')<>[] then
          a=i;
          namef=strsubst(tt(i),'<FILE ',"");
          namef=strsubst(namef,'>',"");
          i=i+1;
        elseif strindex(tt(i),'</FILE ')<>[] then
          b=i;
          len_ex=evstr(b-a-1);
          if len_ex>=0 then
            if strindex(tt(a+1),'<LaTeX force>')<>[] then //LaTeX
              txt=tt(i-len_ex+1:i-1);
              name=basename(namef);
              file_tex=tex_path+lang+'/'+name+'/'+name+'_ex.tex';
              if fileinfo(file_tex)==[] then
                if fileinfo(tex_path+lang+'/')==[] then
                  unix_g(mkdir_cmd+tex_path+lang+'/');
                end
                if fileinfo(tex_path+lang+'/'+name+'/')==[] then
                  unix_g(mkdir_cmd+tex_path+lang+'/'+name);
                end
              end
              printf("Update %s... ",name+'_ex.tex');
              mputl(txt,file_tex);
              k=k+1
              printf("Done\n");
            else //XML
              if strindex(tt(a+1),'<LaTeX')==[] then
                if len_ex==0 then
                  txt=""
                else
                  txt=tt(i-len_ex:i-1)
                end
                if fileinfo(rep_xml+namef)<>[] then
                  printf("Update %s... ",namef);
                  new_tt=put_xml_ex(txt,rep_xml+namef);
                  mputl(new_tt,rep_xml+namef);
                  printf("Done\n");
                  k=k+1; 
                end
              end
            end
          end
          a=0;b=0;
          i=i+1
        else
          i=i+1
        end
      end
      printf("Processed %d files\n",k); 
    else
      printf("file %s not found\n",file_ex);
    end
    
   /////////
   //'desc'
   /////////
   elseif flagn=='desc' then
    if fileinfo(rep_data+file_desc)<>[] then
      printf("Import xml & latex long description...\n");
      tt=mgetl(rep_data+file_desc);
      i=1;
      k=0;
      while i<size(tt,1)
        if strindex(tt(i),'<FILE ')<>[] then
          a=i;
          namef=strsubst(tt(i),'<FILE ',"");
          namef=strsubst(namef,'>',"");
          i=i+1;
        elseif strindex(tt(i),'</FILE ')<>[] then
          b=i;
          len_desc=evstr(b-a-1);
          if len_desc>1 then
            if strindex(tt(a+1),'<LaTeX force>')<>[] then //LaTeX
              txt=tt(i-len_desc+1:i-1);
              name=basename(namef);
              file_tex=tex_path+lang+'/'+name+'/'+name+'_long.tex';
              if fileinfo(file_tex)==[] then
                if fileinfo(tex_path+lang+'/')==[] then
                  unix_g(mkdir_cmd+tex_path+lang+'/');
                end
                if fileinfo(tex_path+lang+'/'+name+'/')==[] then
                  unix_g(mkdir_cmd+tex_path+lang+'/'+name);
                end
              end
              printf("Update %s... ",name+'_long.tex');
              mputl(txt,file_tex);
              k=k+1
              printf("Done\n");
            else //XML
              if strindex(tt(a+1),'<LaTeX')==[] then
                txt=tt(i-len_desc:i-1);
                nb_para=evstr(txt(1)) //nb de paragraphe
                txt_list=list() //initialisation de la liste
                for j=1:nb_para
                  txt_list(j)=list()
                  txt_list(j)(1)=1   //profondeur d'indentation
                  txt_list(j)(2)=""  //le nom du paragraphe
                  txt_list(j)(3)=""  //texte du paragraphe
                end
                //remplit la profondeur d'indentation et les titres
                //trouve les délimiteurs <TEXT> </TEXT>
                l=1;c=[];d=[];
                for j=2:size(txt,1)
                  if strindex(txt(j),'INDENT=')<>[] then
                    txt_list(l)(1)=evstr(strsubst(txt(j),'INDENT=',""))
                  elseif strindex(txt(j),'TITLE=')<>[] then
                    txt_list(l)(2)=strsubst(txt(j),'TITLE=',"")
                  elseif strindex(txt(j),'<TEXT>')<>[] then 
                    c(l)=j;
                  elseif strindex(txt(j),'</TEXT>')<>[] then 
                    d(l)=j;
                    l=l+1
                  end
                end
                //trouve le texte des paragraphes
                for j=1:nb_para
                  txt_list(j)(3)=txt(c(j)+1:d(j)-1)
                end
                if fileinfo(rep_xml+namef)<>[] then
                  printf("Update %s... ",namef);
                  new_tt=put_xml_desc(txt_list,rep_xml+namef);
                  mputl(new_tt,rep_xml+namef);
                  printf("Done\n");
                  k=k+1;
                end
              end
            end
          elseif len_desc==0|len_desc==1 then
           txt_list=list(list());
           if fileinfo(rep_xml+namef)<>[] then
              printf("Update %s... ",namef);
              new_tt=put_xml_desc(txt_list,rep_xml+namef);
              mputl(new_tt,rep_xml+namef);
              printf("Done\n");
              k=k+1;
           end
           //pause
          end
          a=0;b=0;
          i=i+1
        else
          i=i+1
        end
      end
      printf("Processed %d files\n",k); 
    else
      printf("file %s not found\n",file_desc);
    end
    
   /////////////
   //'used_func'
   /////////////
   elseif flagn=='used_func' then
    if fileinfo(rep_data+file_used_func)<>[] then
      printf("Import xml used functions...\n ");
      tt=mgetl(rep_data+file_used_func);
      i=1;
      k=0;
      while i<size(tt,1)
        if strindex(tt(i),'<FILE ')<>[] then
          namef=strsubst(tt(i),'<FILE ',"");
          namef=strsubst(namef,'>',"");
          a=i;
          i=i+1;
        elseif strindex(tt(i),'</FILE ')<>[] then
          b=i;
          len_used_func=evstr(b-a-1);
          if len_used_func<>0 then
            txt=tt(i-len_used_func:i-1);
            if fileinfo(rep_xml+namef)<>[] then
              printf("Update %s... ",namef);
              new_tt=put_xml_used_func(txt,rep_xml+namef);
              mputl(new_tt,rep_xml+namef);
              printf("Done\n");
              k=k+1;
            end
          end
          a=0;b=0;
          i=i+1
        else
          i=i+1
        end
      end
      printf("Processed %d files\n",k);
    else
      printf("file %s not found\n",file_used_func);
    end      
    
   //////////
   //'biblio'
   //////////
   elseif flagn=='biblio' then
    if fileinfo(rep_data+file_biblio)<>[] then
      printf("Import xml & latex bibliography...\n ");
      tt=mgetl(rep_data+file_biblio);
      i=1;
      k=0;
      while i<size(tt,1)
        if strindex(tt(i),'<FILE ')<>[] then
          a=i;
          namef=strsubst(tt(i),'<FILE ',"");
          namef=strsubst(namef,'>',"");
          i=i+1;
        elseif strindex(tt(i),'</FILE ')<>[] then
          b=i;
          len_biblio=evstr(b-a-1);
          if len_biblio<>0 then
            if strindex(tt(a+1),'<LaTeX force>')<>[] then //LaTeX
              txt=tt(i-len_biblio+1:i-1);
              name=basename(namef);
              file_tex=tex_path+lang+'/'+name+'/'+name+'_bib.tex';
              if fileinfo(file_tex)==[] then
                if fileinfo(tex_path+lang+'/')==[] then
                  unix_g(mkdir_cmd+tex_path+lang+'/');
                end
                if fileinfo(tex_path+lang+'/'+name+'/')==[] then
                  unix_g(mkdir_cmd+tex_path+lang+'/'+name);
                end
              end
              printf("Update %s... ",name+'_bib.tex');
              mputl(txt,file_tex);
              k=k+1
              printf("Done\n");
            else //XML
              if strindex(tt(a+1),'<LaTeX')==[] then              
                txt=tt(i-len_biblio:i-1)
                if fileinfo(rep_xml+namef)<>[] then
                  printf("Update %s... ",namef);
                  new_tt=put_xml_biblio(txt,rep_xml+namef);
                  mputl(new_tt,rep_xml+namef);
                  printf("Done\n");
                  k=k+1; 
                end
              end
            end
          end
          a=0;b=0;
          i=i+1
        else
          i=i+1
        end
      end
      printf("Processed %d files\n",k); 
    else
      printf("file %s not found\n",file_biblio);
    end      
       
   //////////////
   //SPECIALDESC
   /////////////
   elseif flagn=='SPECIALDESC' then
    if fileinfo(rep_data+file_spec_desc)<>[] then
      printf("Import latex special description...\n");
      tt=mgetl(rep_data+file_spec_desc);
      i=1;
      k=0;
      while i<size(tt,1)
        if strindex(tt(i),'<FILE ')<>[] then
          a=i;
          namef=strsubst(tt(i),'<FILE ',"");
          namef=strsubst(namef,'>',"");
          i=i+1;
        elseif strindex(tt(i),'</FILE ')<>[] then
          b=i;
          len_spec_desc=evstr(b-a-1);
          if len_spec_desc<>0 then
              txt=tt(i-len_spec_desc:i-1);
              name=basename(namef);
              file_tex=tex_path+lang+'/'+name+'/SPECIALDESC';
              if fileinfo(file_tex)==[] then
                if fileinfo(tex_path+lang+'/')==[] then
                  unix_g(mkdir_cmd+tex_path+lang+'/');
                end
                if fileinfo(tex_path+lang+'/'+name+'/')==[] then
                  unix_g(mkdir_cmd+tex_path+lang+'/'+name);
                end
              end
              printf("Update %s... ",name+'/SPECIALDESC');
              mputl(txt,file_tex);
              k=k+1;
              printf("Done\n");
          end
          a=0;b=0;
          i=i+1;
        else
          i=i+1;
        end
      end
      printf("Processed %d files\n",k);
    else
      printf("file %s not found\n",file_spec_desc);
    end
    
   //////////////
   //call_seq
   /////////////
   elseif flagn=='call_seq' then
      if fileinfo(rep_data+file_call_seq)<>[] then
      printf("Import xml call_seq...\n");
      tt=mgetl(rep_data+file_call_seq);
      i=1;
      k=0;
      a=0;
      b=0;
      while i<size(tt,1)
        if strindex(tt(i),'<FILE ')<>[] then
          a=i;
          namef=strsubst(tt(i),'<FILE ',"");
          namef=strsubst(namef,'>',"");
          i=i+1
        elseif strindex(tt(i),'</FILE ')<>[] then
          b=i;
          num_call_seq=evstr(b-a-1);
          if num_call_seq>=0 then
            if num_call_seq==0 then
             txt=""
            else
             txt=tt(i-num_call_seq:i-1)
            end
            if fileinfo(rep_xml+namef)<>[] then
              printf("Update %s... ",namef);
              new_tt=put_xml_call_seq(txt,rep_xml+namef);
              mputl(new_tt,rep_xml+namef);
              printf("Done\n");
              k=k+1;
            end
          end
          a=0;b=0;
          i=i+1
        else
         i=i+1
        end 
      end
      printf("Processed %d files\n",k);
    else
      printf("file %s not found\n",file_call_seq);
    end
    
   else 
    printf("bad flag\n");    
   end //fin if
 end //fin for
endfunction 

Authors

IRCOM Group Alan Layec