parser.h 1.9 KB

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