"SfR Fresh" - the SfR Freeware/Shareware Archive

Member "mpdist-3.7.1/mimep/ertf2latex/comliste.c" of archive mpdist-3.7.1.tar.gz:


As a special service "SfR Fresh" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. That can be also achieved for any archive member file by clicking within an archive contents listing on the first character of the file(path) respectively on the according byte size field.
    1 
    2 /*
    3  * $Header: /cvsroot/mpdist/mpdist/mimep/ertf2latex/comliste.c,v 1.1.1.1 2002/04/12 16:47:26 richbastard Exp $
    4  *
    5  * Copyright (c) Mikael Cam. All rights reserved.
    6  *
    7  * This software is free software; you can redistribute it and/or modify it
    8  * under the terms of the GNU Library General Public License as published by
    9  * the Free Software Foundation; either version 2 of the License, or (at your
   10  * option) any later version.
   11  *
   12  * This software is distributed in the hope that it will be useful, but WITHOUT
   13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   14  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
   15  * License for more details.
   16  *
   17  * You should have received a copy of the GNU Library General Public License
   18  * along with this software; if not, write to the Free Software Foundation,
   19  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
   20  */
   21 
   22 /*
   23  * Module  : comliste.c   Auteur               : Mikael CAM
   24  * Cadre   : Projet Mimep  Derniere M.A.J.     :
   25  *
   26  * Version : OK
   27  *
   28  * Objet   : Gestion de la liste des dernieres commandes  de texte enrichi.
   29  */
   30 
   31 #include "comliste.h"
   32 
   33 #define  TRUE   1
   34 #define  FALSE  0
   35 
   36 static int _TRACE = 0;
   37 
   38 /* $PROCEDURE CreeListe: Creation de la liste des commandes. */
   39 
   40 void
   41 CreeListe(Liste_com *l)
   42 {
   43     l->courant = NULL;
   44     l->tete    = NULL;
   45     l->queue   = NULL;
   46 }
   47 
   48 
   49 /* $PROCEDURE suivant: Positionnement sur le suivant dans la liste. */
   50 
   51 static format_com *
   52 suivant(Liste_com *l)
   53 {
   54     if (l->courant != l->queue) {
   55         l->courant = l->courant->suivant;
   56     }
   57 
   58     return(l->courant);
   59 }
   60 
   61 
   62 /* $PROCEDURE courant: Renvoie un pointeur sur l'element courant. */
   63 
   64 format_com *
   65 courant(Liste_com *l)
   66 {
   67     return(l->courant);
   68 }
   69 
   70 
   71 /* $PROCEDURE position_tete: Positionnement sur la tete de liste. */
   72 
   73 format_com *
   74 position_tete(Liste_com *l)
   75 {
   76     l->courant = l->tete;
   77 
   78     return(l->tete);
   79 }
   80 
   81 
   82 /* $PROCEDURE AjouteListe: Ajout d'un element dans la liste. */
   83 
   84 void
   85 AjouteListe(Liste_com *l, format_com *p)
   86 {
   87     if (l->tete == NULL) {
   88         l->tete = p;
   89         l->queue = p;
   90         l->courant = p;
   91     }
   92 
   93     l->queue->suivant = p;
   94     p->precedent = l->queue;
   95     l->queue = p;
   96 }
   97 
   98 
   99 /* $PROCEDURE OteEltListe: Ote un element dans la liste. */
  100 
  101 void
  102 OteEltListe(Liste_com * l, format_com * p)
  103 {
  104     if ((p != l->tete) && (p != l->queue)) {
  105         p->precedent->suivant = p->suivant;
  106         p->suivant->precedent = p->precedent;
  107         FREE(p);
  108     } else if ((p == l->queue) && (p != l->tete)) {
  109         p->precedent->suivant = NULL;
  110         l->queue = p->precedent;
  111         FREE(p);
  112     } else if ((p == l->tete) && (p != l->queue)) {
  113         p->suivant->precedent = NULL;
  114         l->tete = p->suivant;
  115         FREE(p);
  116     } else {
  117         l->tete = NULL;
  118         l->queue = NULL;
  119         l->courant = NULL;
  120         /* FREE(p); */
  121     }
  122 }
  123 
  124 
  125 /* $PROCEDURE FinListe: Verifie si l'on est en fin de liste. */
  126 
  127 int
  128 FinListe(Liste_com *l)
  129 {
  130     if (l->courant == l->queue) {
  131         return(TRUE);
  132     } else {
  133         return(FALSE);
  134     }
  135 }
  136 
  137 
  138 /* $PROCEDURE remplie_param: Remplie les parametres d'un element de la liste. */
  139 
  140 /* ARGSUSED */
  141 void
  142 remplie_comm(format_com *p, Command c, Liste_com *l)
  143 {
  144     Command commande = (Command) malloc((sizeof(char)) * strlen(c));
  145 
  146     STRCPY(commande, c);
  147     p->c_name = commande;
  148 }
  149 
  150 
  151 /* $PROCEDURE Trouve: essaie de trouver un element donne de la liste
  152  *                    correspondant a la fenetre passee en parametres.
  153  */
  154 
  155 format_com *
  156 Trouve(Command c, Liste_com *l)
  157 {
  158     format_com *cp_cour;
  159     int existe;
  160 
  161 /* Recherche des derniers parametres de la fenetre concernee */
  162 
  163     if (_TRACE) {
  164         FPRINTF(stdout, " Recherche \n");
  165     }
  166 
  167     existe = FALSE;
  168     cp_cour = position_tete(l);
  169 
  170     if ((cp_cour) && (!strcmp(cp_cour->c_name, c))) {
  171         existe = TRUE;
  172     } else {
  173         while ((!FinListe(l)) && (!existe)) {
  174             cp_cour = suivant(l);
  175 
  176             if (!strcmp(cp_cour->c_name, c)) {
  177                 existe = TRUE;
  178             }
  179 
  180             if (_TRACE) {
  181                 FPRINTF(stdout, " Recherche: Command: %s\n", cp_cour->c_name);
  182             }
  183         }
  184     }
  185 
  186     if (existe) {
  187         return(cp_cour);
  188     } else {
  189         return(NULL);
  190     }
  191 }