commit 98e31e1e1a8cd8fc43f969586cbdf3f89957d527
parent d991ae66d4e94a0b42fa6044d9f89688a3292a95
Auteur: Selve <selve@asteride.xyz>
Date: Sun, 19 Nov 2023 15:16:33 -0500
implémentation des blocs
Ils permettent d'échapper certains caractères avec plus de sérénité.
Diffstat:
M | aplat.c | | | 67 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- |
1 file changed, 62 insertions(+), 5 deletions(-)
diff --git a/aplat.c b/aplat.c
@@ -23,6 +23,7 @@ static int transformer(FILE *);
static int prch_jeton(FILE *, struct tampon *, int);
static int afficher_ligne(struct tampon *, struct tampon *, int *);
static int guillemets(FILE *, struct tampon *);
+static int bloc(FILE *, struct tampon *);
char *nom_prog; /* nom du programme */
@@ -169,6 +170,7 @@ static int
prch_jeton(FILE *f, struct tampon *tp, int tp_type)
{
int c;
+ int npar; /* nombre de guillemets */
assert(f != NULL);
assert(tp != NULL);
@@ -187,14 +189,30 @@ prch_jeton(FILE *f, struct tampon *tp, int tp_type)
do {
switch (c) {
- case ' ': case '\t': case '\n':
- return JT_ATM;
case '(': case ')':
ungetc(c, f);
+ /* CASCADE */
+ case ' ': case '\t': case '\n':
return JT_ATM;
case '"':
- if (guillemets(f, tp) == EOF)
- return EOF;
+ for (npar = 1; (c = getc(f)) == '"'; npar++)
+ if (c == EOF)
+ return EOF;
+ while (c != '\n') /* ignorer la ligne */
+ if ((c = getc(f)) == EOF)
+ return EOF;
+ if (npar == 3) {
+ if (bloc(f, tp) == EOF)
+ return EOF;
+ continue;
+ } else {
+ while (npar-- > 0)
+ tp_ecr('"', tp);
+ }
+ ungetc(c, f);
+ if (npar % 2 == 1)
+ if (guillemets(f, tp) == EOF)
+ return EOF;
continue;
case ':':
if (tp_type == TP_TYPE_ETQ)
@@ -283,8 +301,47 @@ guillemets(FILE *f, struct tampon *tp)
tp_ecr('\\', tp);
/* CASCADE */
default:
- tp_ecr(c, tp);
+ tp_ecr(c, tp);
}
}
return c;
}
+
+static int
+bloc(FILE *f, struct tampon *tp)
+{
+ int c;
+ int npar;
+
+ assert(f != NULL);
+ assert(tp != NULL);
+
+ while ((c = getc(f)) != EOF) {
+ switch (c) {
+ case '\n':
+ tp_ecr('\\', tp);
+ tp_ecr('n', tp);
+ continue;
+ case '\t':
+ tp_ecr('\\', tp);
+ tp_ecr('t', tp);
+ continue;
+ case '"':
+ for (npar = 1; (c = getc(f)) == '"'; npar++)
+ ;
+ if (npar > 3 || (npar == 3 && c != '!')) {
+ return c;
+ }
+ ungetc(c, f);
+ while (npar-- > 0)
+ tp_ecr('"', tp);
+ continue;
+ case '\\':
+ tp_ecr('\\', tp);
+ /* CASCADE */
+ default:
+ tp_ecr(c, tp);
+ }
+ }
+ return EOF;
+}