Created
May 21, 2019 16:11
-
-
Save T12z/6b0d99eb190aacb0fa49003a37d7ad78 to your computer and use it in GitHub Desktop.
Filter out annotations in xscade files (e.g., scade_model_without_unused.scade)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
============================================================================ | |
Name : sweep_scade.c | |
Author : Thorsten Schulz <thorsten.schulz@uni-rostock.de> | |
Version : | |
Copyright : (c) 2019 with terms of EUPL | |
Description : A stream filter to purge all the _x_scade annotations in the | |
final blob before code generation. Mostly for stats. | |
============================================================================ | |
*/ | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <ctype.h> | |
char *on = "#pragma"; | |
char *off= "#end"; | |
int search(char *buf, int in_pragma) { | |
char *pos; | |
if (in_pragma) { | |
if ((pos = strstr(buf, off))) { | |
pos += strlen(off); | |
if (isblank(*pos)) pos++; /* some trimming */ | |
if (*pos == '\r') pos++; | |
if (*pos == '\n') pos++; | |
return search(pos, 0); | |
} | |
} else { | |
if ((pos = strstr(buf, on))) { | |
char *bt = pos; | |
while (bt != buf) { | |
if ((bt-1) >= buf && !isblank(*(bt-1))) break; /* do not delete intermediate blank */ | |
if ((bt-2) >= buf && !isblank(*(bt-2))) break; /* do not delete intermediate blank */ | |
bt--; | |
} | |
*bt = 0; | |
fputs(buf, stdout); | |
in_pragma = search(pos+strlen(on), 1); | |
} else | |
fputs(buf, stdout); | |
} | |
return in_pragma; | |
} | |
int main(void) { | |
char buf[2048]; /* typically (x)scade files are shorter than 256 chars */ | |
int in_pragma = 0; | |
while (fgets(buf, sizeof(buf), stdin)) | |
in_pragma = search(buf, in_pragma); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment