File:  [local] / rpl / src / instructions_a5.c
Revision 1.41: download - view: text, annotated - select for diffs - revision graph
Tue Feb 26 19:56:13 2013 UTC (11 years, 2 months ago) by bertrand
Branches: MAIN
CVS tags: rpl-4_1_12, HEAD
Mise à jour des copyrights.

    1: /*
    2: ================================================================================
    3:   RPL/2 (R) version 4.1.12
    4:   Copyright (C) 1989-2013 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:   Fonction 'alarm'
   29: ================================================================================
   30:   Entrées : pointeur sur une structure struct_processus
   31: --------------------------------------------------------------------------------
   32:   Sorties :
   33: --------------------------------------------------------------------------------
   34:   Effets de bord : néant
   35: ================================================================================
   36: */
   37: 
   38: void
   39: instruction_alarm(struct_processus *s_etat_processus)
   40: {
   41:     double                      duree;
   42: 
   43:     int                         code_retour;
   44:     int                         erreur;
   45: 
   46:     logical1                    specification_date;
   47: 
   48:     struct_liste_chainee        *l_element_courant;
   49: 
   50:     struct_objet                *s_objet_argument;
   51: 
   52:     struct timeb                st;
   53: 
   54:     struct timespec             attente;
   55: 
   56:     struct timeval              debut_interruption;
   57:     struct timeval              duree_interruption;
   58:     struct timeval              fin_interruption;
   59: 
   60:     struct tm                   *s_time_actuel;
   61:     struct tm                   s_time_alarme;
   62:     struct tm                   s_time_registre;
   63: 
   64:     time_t                      alarme;
   65: 
   66:     unsigned long               nombre_elements;
   67: 
   68:     (*s_etat_processus).erreur_execution = d_ex;
   69: 
   70:     if ((*s_etat_processus).affichage_arguments == 'Y')
   71:     {
   72:         printf("\n  ALARM ");
   73: 
   74:         if ((*s_etat_processus).langue == 'F')
   75:         {
   76:             printf("(suspension du processus jusqu'à un instant spécifié)\n\n");
   77:         }
   78:         else
   79:         {
   80:             printf("(wait until timestamp)\n\n");
   81:         }
   82: 
   83:         printf("    1: %s\n\n", d_LST);
   84: 
   85:         if ((*s_etat_processus).langue == 'F')
   86:         {
   87:             printf("  Utilisation :\n\n");
   88:         }
   89:         else
   90:         {
   91:             printf("  Usage:\n\n");
   92:         }
   93: 
   94:         printf("    { hours minutes } ALARM\n");
   95:         printf("    { hours minutes seconds } ALARM\n");
   96:         printf("    { hours minutes seconds day } ALARM\n");
   97:         printf("    { hours minutes seconds day month } ALARM\n");
   98:         printf("    { hours minutes seconds day month year } ALARM\n");
   99: 
  100:         return;
  101:     }
  102:     else if ((*s_etat_processus).test_instruction == 'Y')
  103:     {
  104:         (*s_etat_processus).nombre_arguments = 1;
  105:         return;
  106:     }
  107: 
  108:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  109:     {
  110:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
  111:         {
  112:             return;
  113:         }
  114:     }
  115: 
  116:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  117:             &s_objet_argument) == d_erreur)
  118:     {
  119:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  120:         return;
  121:     }
  122: 
  123:     if ((*s_objet_argument).type == LST)
  124:     {
  125:         l_element_courant = (*s_objet_argument).objet;
  126:         nombre_elements = 0;
  127: 
  128:         while(l_element_courant != NULL)
  129:         {
  130:             if ((*(*l_element_courant).donnee).type != INT)
  131:             {
  132:                 (*s_etat_processus).erreur_execution =
  133:                         d_ex_erreur_type_argument;
  134: 
  135:                 liberation(s_etat_processus, s_objet_argument);
  136:                 return;
  137:             }
  138: 
  139:             l_element_courant = (*l_element_courant).suivant;
  140:             nombre_elements++;
  141:         }
  142: 
  143:         if ((nombre_elements < 2) || (nombre_elements > 6))
  144:         {
  145:             (*s_etat_processus).erreur_execution =
  146:                     d_ex_argument_invalide;
  147: 
  148:             liberation(s_etat_processus, s_objet_argument);
  149:             return;
  150:         }
  151: 
  152:         st.time = time(NULL);
  153:         s_time_actuel = localtime(&(st.time));
  154: 
  155:         l_element_courant = (*s_objet_argument).objet;
  156:         s_time_alarme.tm_hour = (*((integer8 *) (*(*l_element_courant)
  157:                 .donnee).objet));
  158:         l_element_courant = (*l_element_courant).suivant;
  159:         s_time_alarme.tm_min = (*((integer8 *) (*(*l_element_courant)
  160:                 .donnee).objet));
  161:         l_element_courant = (*l_element_courant).suivant;
  162: 
  163:         specification_date = d_faux;
  164: 
  165:         if (l_element_courant != NULL)
  166:         {
  167:             s_time_alarme.tm_sec = (*((integer8 *) (*(*l_element_courant)
  168:                     .donnee).objet));
  169:             l_element_courant = (*l_element_courant).suivant;
  170: 
  171:             if (l_element_courant != NULL)
  172:             {
  173:                 specification_date = d_vrai;
  174: 
  175:                 s_time_alarme.tm_mday = (*((integer8 *) (*(*l_element_courant)
  176:                         .donnee).objet));
  177:                 l_element_courant = (*l_element_courant).suivant;
  178: 
  179:                 if (l_element_courant != NULL)
  180:                 {
  181:                     s_time_alarme.tm_mon = (*((integer8 *)
  182:                             (*(*l_element_courant).donnee).objet)) - 1;
  183:                     l_element_courant = (*l_element_courant).suivant;
  184: 
  185:                     if (l_element_courant != NULL)
  186:                     {
  187:                         s_time_alarme.tm_year = (*((integer8 *)
  188:                                 (*(*l_element_courant).donnee).objet))
  189:                                 - 1900;
  190:                         l_element_courant = (*l_element_courant).suivant;
  191:                     }
  192:                     else
  193:                     {
  194:                         s_time_alarme.tm_year = (*s_time_actuel).tm_year;
  195:                     }
  196:                 }
  197:                 else
  198:                 {
  199:                     s_time_alarme.tm_mon = (*s_time_actuel).tm_mon;
  200:                     s_time_alarme.tm_year = (*s_time_actuel).tm_year;
  201:                 }
  202:             }
  203:             else
  204:             {
  205:                 s_time_alarme.tm_mday = (*s_time_actuel).tm_mday;
  206:                 s_time_alarme.tm_mon = (*s_time_actuel).tm_mon;
  207:                 s_time_alarme.tm_year = (*s_time_actuel).tm_year;
  208:             }
  209:         }
  210:         else
  211:         {
  212:             s_time_alarme.tm_sec = 0;
  213:             s_time_alarme.tm_mday = (*s_time_actuel).tm_mday;
  214:             s_time_alarme.tm_mon = (*s_time_actuel).tm_mon;
  215:             s_time_alarme.tm_year = (*s_time_actuel).tm_year;
  216:         }
  217: 
  218:         s_time_alarme.tm_isdst = 0;
  219:         s_time_registre = s_time_alarme;
  220:         alarme = mktime(&s_time_alarme);
  221: 
  222:         if ((s_time_alarme.tm_sec != s_time_registre.tm_sec) ||
  223:                 (s_time_alarme.tm_min != s_time_registre.tm_min) ||
  224:                 (s_time_alarme.tm_hour != s_time_registre.tm_hour) ||
  225:                 (s_time_alarme.tm_mday != s_time_registre.tm_mday) ||
  226:                 (s_time_alarme.tm_mon != s_time_registre.tm_mon) ||
  227:                 (s_time_alarme.tm_year != s_time_registre.tm_year))
  228:         {
  229:             (*s_etat_processus).erreur_execution =
  230:                     d_ex_argument_invalide;
  231: 
  232:             liberation(s_etat_processus, s_objet_argument);
  233:             return;
  234:         }
  235: 
  236:         while((duree = difftime(alarme, st.time)) < 0)
  237:         {
  238:             if (specification_date == d_vrai)
  239:             {
  240:                 (*s_etat_processus).erreur_execution =
  241:                         d_ex_argument_invalide;
  242: 
  243:                 liberation(s_etat_processus, s_objet_argument);
  244:                 return;
  245:             }
  246: 
  247:             s_time_alarme.tm_mday++;
  248:             alarme = mktime(&s_time_alarme);
  249:         }
  250: 
  251:         attente.tv_nsec = (long) ((duree - (attente.tv_sec =
  252:                 (long) floor(duree))) * 1000000000);
  253: 
  254:         if ((*s_etat_processus).profilage == d_vrai)
  255:         {
  256:             profilage(s_etat_processus, "Sleep function (ALARM)");
  257: 
  258:             if ((*s_etat_processus).erreur_systeme != d_es)
  259:             {
  260:                 return;
  261:             }
  262:         }
  263: 
  264:         do
  265:         {
  266:             code_retour = nanosleep(&attente, &attente);
  267:             erreur = errno;
  268: 
  269:             if (code_retour == -1)
  270:             {
  271:                 gettimeofday(&debut_interruption, NULL);
  272: 
  273:                 scrutation_injection(s_etat_processus);
  274: 
  275:                 if ((*s_etat_processus).nombre_interruptions_non_affectees != 0)
  276:                 {
  277:                     affectation_interruptions_logicielles(s_etat_processus);
  278:                 }
  279: 
  280:                 if ((*s_etat_processus).nombre_interruptions_en_queue != 0)
  281:                 {
  282:                     traitement_interruptions_logicielles(s_etat_processus);
  283:                 }
  284: 
  285:                 gettimeofday(&fin_interruption, NULL);
  286: 
  287:                 if (fin_interruption.tv_usec < debut_interruption.tv_usec)
  288:                 {
  289:                     duree_interruption.tv_usec = (1000000
  290:                             + fin_interruption.tv_usec)
  291:                             - debut_interruption.tv_usec;
  292:                     duree_interruption.tv_sec = fin_interruption.tv_sec
  293:                             - (debut_interruption.tv_sec + 1);
  294:                 }
  295:                 else
  296:                 {
  297:                     duree_interruption.tv_usec = fin_interruption.tv_usec
  298:                             - debut_interruption.tv_usec;
  299:                     duree_interruption.tv_sec = fin_interruption.tv_sec
  300:                             - debut_interruption.tv_sec;
  301:                 }
  302: 
  303:                 if (attente.tv_nsec < (1000 * duree_interruption.tv_usec))
  304:                 {
  305:                     attente.tv_nsec = (1000000000 + attente.tv_nsec)
  306:                             - (1000 * duree_interruption.tv_usec);
  307:                     attente.tv_sec = attente.tv_sec
  308:                             - (duree_interruption.tv_sec + 1);
  309:                 }
  310:                 else
  311:                 {
  312:                     attente.tv_nsec = attente.tv_nsec
  313:                             - (1000 * duree_interruption.tv_usec);
  314:                     attente.tv_sec = attente.tv_sec
  315:                             - duree_interruption.tv_sec;
  316:                 }
  317: 
  318:                 if (attente.tv_sec < 0)
  319:                 {
  320:                     code_retour = 0;
  321:                 }
  322:             }
  323:         } while(((code_retour == -1) && (erreur == EINTR))
  324:                 && ((*s_etat_processus).var_volatile_requete_arret == 0));
  325: 
  326:         if ((*s_etat_processus).profilage == d_vrai)
  327:         {
  328:             profilage(s_etat_processus, NULL);
  329:         }
  330:     }
  331:     else
  332:     {
  333:         liberation(s_etat_processus, s_objet_argument);
  334: 
  335:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  336:         return;
  337:     }
  338: 
  339:     liberation(s_etat_processus, s_objet_argument);
  340:     return;
  341: }
  342: 
  343: 
  344: /*
  345: ================================================================================
  346:   Fonction 'atexit'
  347: ================================================================================
  348:   Entrées :
  349: --------------------------------------------------------------------------------
  350:   Sorties :
  351: --------------------------------------------------------------------------------
  352:   Effets de bord : néant
  353: ================================================================================
  354: */
  355: 
  356: void
  357: instruction_atexit(struct_processus *s_etat_processus)
  358: {
  359:     struct_objet        *s_objet_argument;
  360: 
  361:     (*s_etat_processus).erreur_execution = d_ex;
  362: 
  363:     if ((*s_etat_processus).affichage_arguments == 'Y')
  364:     {
  365:         printf("\n  ATEXIT ");
  366: 
  367:         if ((*s_etat_processus).langue == 'F')
  368:         {
  369:             printf("(exécution d'une fonction à la sortie d'une tâche)\n\n");
  370:         }
  371:         else
  372:         {
  373:             printf("(register a function to be called on task exit)\n\n");
  374:         }
  375: 
  376:         printf("    1: %s, %s\n", d_NOM, d_RPN);
  377: 
  378:         return;
  379:     }
  380:     else if ((*s_etat_processus).test_instruction == 'Y')
  381:     {
  382:         (*s_etat_processus).nombre_arguments = 1;
  383:         return;
  384:     }
  385: 
  386:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  387:     {
  388:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
  389:         {
  390:             return;
  391:         }
  392:     }
  393: 
  394:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  395:             &s_objet_argument) == d_erreur)
  396:     {
  397:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  398:         return;
  399:     }
  400: 
  401:     if ((*s_objet_argument).type == NOM)
  402:     {
  403:         liberation(s_etat_processus, (*s_etat_processus).at_exit);
  404:         (*s_etat_processus).at_exit = s_objet_argument;
  405:     }
  406:     else if ((*s_objet_argument).type == RPN)
  407:     {
  408:         liberation(s_etat_processus, (*s_etat_processus).at_exit);
  409:         (*s_etat_processus).at_exit = s_objet_argument;
  410:     }
  411:     else
  412:     {
  413:         liberation(s_etat_processus, s_objet_argument);
  414: 
  415:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  416:         return;
  417:     }
  418: 
  419:     return;
  420: }
  421: 
  422: 
  423: /*
  424: ================================================================================
  425:   Fonction 'atpoke'
  426: ================================================================================
  427:   Entrées :
  428: --------------------------------------------------------------------------------
  429:   Sorties :
  430: --------------------------------------------------------------------------------
  431:   Effets de bord : néant
  432: ================================================================================
  433: */
  434: 
  435: void
  436: instruction_atpoke(struct_processus *s_etat_processus)
  437: {
  438:     struct_objet        *s_objet_argument;
  439: 
  440:     (*s_etat_processus).erreur_execution = d_ex;
  441: 
  442:     if ((*s_etat_processus).affichage_arguments == 'Y')
  443:     {
  444:         printf("\n  ATPOKE ");
  445: 
  446:         if ((*s_etat_processus).langue == 'F')
  447:         {
  448:             printf("(exécution d'une fonction lors de l'injection "
  449:                     "d'une donnée)\n\n");
  450:         }
  451:         else
  452:         {
  453:             printf("(register a function to be called on data injection)\n\n");
  454:         }
  455: 
  456:         printf("    1: %s, %s\n", d_NOM, d_RPN);
  457: 
  458:         return;
  459:     }
  460:     else if ((*s_etat_processus).test_instruction == 'Y')
  461:     {
  462:         (*s_etat_processus).nombre_arguments = 1;
  463:         return;
  464:     }
  465: 
  466:     if (test_cfsf(s_etat_processus, 31) == d_vrai)
  467:     {
  468:         if (empilement_pile_last(s_etat_processus, 1) == d_erreur)
  469:         {
  470:             return;
  471:         }
  472:     }
  473: 
  474:     if (depilement(s_etat_processus, &((*s_etat_processus).l_base_pile),
  475:             &s_objet_argument) == d_erreur)
  476:     {
  477:         (*s_etat_processus).erreur_execution = d_ex_manque_argument;
  478:         return;
  479:     }
  480: 
  481:     if ((*s_objet_argument).type == NOM)
  482:     {
  483:         liberation(s_etat_processus, (*s_etat_processus).at_poke);
  484:         (*s_etat_processus).at_poke = s_objet_argument;
  485:     }
  486:     else if ((*s_objet_argument).type == RPN)
  487:     {
  488:         liberation(s_etat_processus, (*s_etat_processus).at_poke);
  489:         (*s_etat_processus).at_poke = s_objet_argument;
  490:     }
  491:     else
  492:     {
  493:         liberation(s_etat_processus, s_objet_argument);
  494: 
  495:         (*s_etat_processus).erreur_execution = d_ex_erreur_type_argument;
  496:         return;
  497:     }
  498: 
  499:     return;
  500: }
  501: 
  502: // vim: ts=4

CVSweb interface <joel.bertrand@systella.fr>