parser.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * File: parser.h
  3. * Author: Arthur Brandao
  4. *
  5. * Created on 31 octobre 2018
  6. */
  7. #ifndef PARSER_H
  8. #define PARSER_H
  9. /* --- Include --- */
  10. #include "constante.h"
  11. /* --- Structure --- */
  12. typedef struct {
  13. char* cmd; //La commande en string
  14. char* name; //Le nom de la commande
  15. int argc; //Le nombre d'argument
  16. char** argv; //Les arguments
  17. int input; //Descripteur de fichier d'entré
  18. int output; //Descripteur de fichier de sortie
  19. int error; //Descripteur de fihier d'erreur
  20. int next; //Lien avec la prochaine commande
  21. } Command;
  22. typedef struct {
  23. Command** cmd; //Tableau avec toutes les commandes
  24. int length; //Taille du tableau
  25. boolean bck; //Si l'ensemble de commande se fait en fond
  26. } CommandTab;
  27. /* --- Fonctions --- */
  28. /**
  29. * Parse une ligne de commande (separe les commandes et repere le lien entre elle)
  30. * @param CommandTab* La structure contenant le resultat
  31. * @param char* La ligne de commande à parser
  32. * @return int SHELL_OK si réussite, SHELL_ERR sinon
  33. */
  34. int parse_line(CommandTab*, char*);
  35. /**
  36. * Parse une commande (repere changement entrée sortie, wildcard, découpe les
  37. * arguments)
  38. * @param Command* La structure commande à parser (initialisée dans une
  39. * CommandTab par la fonction parse_line)
  40. * @return int SHELL_OK si réussite, SHELL_ERR sinon
  41. */
  42. int parse_command(Command*);
  43. /**
  44. * Parse toutes les commandes d'un CommandTab
  45. * @param CommandTab* La structure contenant les commandes initialisée dans
  46. * la fonctions parse_line)
  47. * @return int SHELL_OK si réussite, SHELL_FAIL si le parse d'une des commandes
  48. * échoue
  49. */
  50. int parse_all_command(CommandTab*);
  51. /**
  52. * Vide un structure CommandTab
  53. * @param CommandTab* La structure à nettoyer
  54. */
  55. void clean_command(CommandTab*);
  56. #endif /* PARSER_H */