Annotation of rpl/src/formateur_flux.c, revision 1.1

1.1     ! bertrand    1: /*
        !             2: ================================================================================
        !             3:   RPL/2 (R) version 4.0.21
        !             4:   Copyright (C) 1989-2011 Dr. BERTRAND Joël
        !             5: 
        !             6:   This file is part of RPL/2.
        !             7: 
        !             8:   RPL/2 is free software; you can redistribute it and/or modify it
        !             9:   under the terms of the CeCILL V2 License as published by the french
        !            10:   CEA, CNRS and INRIA.
        !            11:  
        !            12:   RPL/2 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 CeCILL V2 License
        !            15:   for more details.
        !            16:  
        !            17:   You should have received a copy of the CeCILL License
        !            18:   along with RPL/2. If not, write to info@cecill.info.
        !            19: ================================================================================
        !            20: */
        !            21: 
        !            22: 
        !            23: #include "rpl-conv.h"
        !            24: 
        !            25: 
        !            26: /*
        !            27: ================================================================================
        !            28:   Routine de formation des données pour l'envoi de flux binaires
        !            29: ================================================================================
        !            30:   Entrées : structure sur l'état du processus et objet à afficher
        !            31: --------------------------------------------------------------------------------
        !            32:   Sorties : chaine de caractères
        !            33: --------------------------------------------------------------------------------
        !            34:   Effets de bord : néant
        !            35: ================================================================================
        !            36: */
        !            37: 
        !            38: unsigned char *
        !            39: formateur_flux(struct_processus *s_etat_processus, unsigned char *donnees,
        !            40:        long *longueur)
        !            41: {
        !            42:    unsigned char           *chaine;
        !            43: 
        !            44:    unsigned char           *ptr_ecriture;
        !            45:    unsigned char           *ptr_lecture;
        !            46: 
        !            47:    if ((chaine = malloc((strlen(donnees) + 1) * sizeof(unsigned char)))
        !            48:            == NULL)
        !            49:    {
        !            50:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
        !            51:        return(NULL);
        !            52:    }
        !            53: 
        !            54:    ptr_lecture = donnees;
        !            55:    ptr_ecriture = chaine;
        !            56: 
        !            57:    while((*ptr_lecture) != d_code_fin_chaine)
        !            58:    {
        !            59:        (*ptr_ecriture) = (*ptr_lecture);
        !            60: 
        !            61:        // Début de la séquence d'échappement
        !            62: 
        !            63:        if ((*ptr_lecture) == '\\')
        !            64:        {
        !            65:            if ((*(ptr_lecture + 1)) == '"')
        !            66:            {
        !            67:                ptr_lecture++;
        !            68:                (*ptr_ecriture) = '\"';
        !            69:            }
        !            70:            else if ((*(ptr_lecture + 1)) == 'b')
        !            71:            {
        !            72:                ptr_lecture++;
        !            73:                (*ptr_ecriture) = '\b';
        !            74:            }
        !            75:            else if ((*(ptr_lecture + 1)) == 'n')
        !            76:            {
        !            77:                ptr_lecture++;
        !            78:                (*ptr_ecriture) = '\n';
        !            79:            }
        !            80:            else if ((*(ptr_lecture + 1)) == 't')
        !            81:            {
        !            82:                ptr_lecture++;
        !            83:                (*ptr_ecriture) = '\t';
        !            84:            }
        !            85:            else if ((*(ptr_lecture + 1)) == 'x')
        !            86:            {
        !            87:                ptr_lecture += 2;
        !            88: 
        !            89:                if ((*ptr_lecture) != d_code_fin_chaine)
        !            90:                {
        !            91:                    if ((*(ptr_lecture + 1)) != d_code_fin_chaine)
        !            92:                    {
        !            93:                        logical1        erreur;
        !            94:                        unsigned char   ec;
        !            95: 
        !            96:                        erreur = d_faux;
        !            97: 
        !            98:                        switch(*ptr_lecture)
        !            99:                        {
        !           100:                            case '0':
        !           101:                            case '1':
        !           102:                            case '2':
        !           103:                            case '3':
        !           104:                            case '4':
        !           105:                            case '5':
        !           106:                            case '6':
        !           107:                            case '7':
        !           108:                            case '8':
        !           109:                            case '9':
        !           110:                                ec = (*ptr_lecture) - '0';
        !           111:                                break;
        !           112: 
        !           113:                            case 'A':
        !           114:                            case 'B':
        !           115:                            case 'C':
        !           116:                            case 'D':
        !           117:                            case 'E':
        !           118:                            case 'F':
        !           119:                                ec = ((*ptr_lecture) - 'A') + 10;
        !           120:                                break;
        !           121: 
        !           122:                            default:
        !           123:                                ec = 0;
        !           124:                                erreur = d_vrai;
        !           125:                                break;
        !           126:                        }
        !           127: 
        !           128:                        ec *= 0x10;
        !           129:                        ptr_lecture++;
        !           130: 
        !           131:                        switch(*ptr_lecture)
        !           132:                        {
        !           133:                            case '0':
        !           134:                            case '1':
        !           135:                            case '2':
        !           136:                            case '3':
        !           137:                            case '4':
        !           138:                            case '5':
        !           139:                            case '6':
        !           140:                            case '7':
        !           141:                            case '8':
        !           142:                            case '9':
        !           143:                                ec += (*ptr_lecture) - '0';
        !           144:                                break;
        !           145: 
        !           146:                            case 'A':
        !           147:                            case 'B':
        !           148:                            case 'C':
        !           149:                            case 'D':
        !           150:                            case 'E':
        !           151:                            case 'F':
        !           152:                                ec += ((*ptr_lecture) - 'A') + 10;
        !           153:                                break;
        !           154: 
        !           155:                            default:
        !           156:                                erreur = d_vrai;
        !           157:                                break;
        !           158:                        }
        !           159: 
        !           160:                        (*ptr_ecriture) = ec;
        !           161: 
        !           162:                        if (erreur == d_vrai)
        !           163:                        {
        !           164:                            if ((*s_etat_processus).langue == 'F')
        !           165:                            {
        !           166:                                printf("+++Information : "
        !           167:                                        "Séquence d'échappement "
        !           168:                                        "inconnue [%d]\n",
        !           169:                                        (int) getpid());
        !           170:                            }
        !           171:                            else
        !           172:                            {
        !           173:                                printf("+++Warning : Unknown "
        !           174:                                        "escape code "
        !           175:                                        "[%d]\n", (int) getpid());
        !           176:                            }
        !           177:                        }
        !           178:                    }
        !           179:                    else
        !           180:                    {
        !           181:                        if ((*s_etat_processus).langue == 'F')
        !           182:                        {
        !           183:                            printf("+++Information : "
        !           184:                                    "Séquence d'échappement "
        !           185:                                    "inconnue [%d]\n", (int) getpid());
        !           186:                        }
        !           187:                        else
        !           188:                        {
        !           189:                            printf("+++Warning : Unknown escape code "
        !           190:                                    "[%d]\n", (int) getpid());
        !           191:                        }
        !           192:                    }
        !           193:                }
        !           194:                else
        !           195:                {
        !           196:                    if ((*s_etat_processus).langue == 'F')
        !           197:                    {
        !           198:                        printf("+++Information : "
        !           199:                                "Séquence d'échappement "
        !           200:                                "inconnue [%d]\n", (int) getpid());
        !           201:                    }
        !           202:                    else
        !           203:                    {
        !           204:                        printf("+++Warning : Unknown escape code "
        !           205:                                "[%d]\n", (int) getpid());
        !           206:                    }
        !           207:                }
        !           208:            }
        !           209:            else if ((*(ptr_lecture + 1)) == '\\')
        !           210:            {
        !           211:                ptr_lecture++;
        !           212:            }
        !           213:            else
        !           214:            {
        !           215:                if ((*s_etat_processus).langue == 'F')
        !           216:                {
        !           217:                    printf("+++Information : Séquence d'échappement "
        !           218:                            "inconnue [%d]\n", (int) getpid());
        !           219:                }
        !           220:                else
        !           221:                {
        !           222:                    printf("+++Warning : Unknown escape code "
        !           223:                            "[%d]\n", (int) getpid());
        !           224:                }
        !           225:            }
        !           226:        }
        !           227: 
        !           228:        ptr_ecriture++;
        !           229:        ptr_lecture++;
        !           230:    }
        !           231: 
        !           232:    (*ptr_ecriture) = d_code_fin_chaine;
        !           233: 
        !           234:    if ((chaine = realloc(chaine, ((((*longueur) = ptr_ecriture - chaine)) + 1)
        !           235:            * sizeof(unsigned char))) == NULL)
        !           236:    {
        !           237:        (*s_etat_processus).erreur_systeme = d_es_allocation_memoire;
        !           238:        return(NULL);
        !           239:    }
        !           240: 
        !           241:    return(chaine);
        !           242: }
        !           243: 
        !           244: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>