Generate an index (or tag) file of AVS functions to allow these items to be easily located by a text editor (vi).

/*  Synopsis:     avstags [ avs_file ...]
 *  Description:  Create vi Style tags for OpenLink Endur/Findur AVS files
 */

%{
#include 
#include 
#include 
#include "emsg.h"
static void reset_input_line();
%}
%option noyywrap

  static char *avs_filename = "";
  static int braces = 0, comment = 0;
  static char identifer[32 + 1], input_line[2048];
  static int id_indx = 0, line_indx = 0;
  static int ch, prev_ch;
  static char tag[sizeof(identifer)], tag_line[sizeof(input_line)];
  static int tagline_indx = 0, tag_flag = 0, tagline_flag = 0;

%%

\/\*    { comment = 1; }
\*\/    { comment = 0; }
\/\/    { strcat(input_line, yytext); line_indx+= yyleng;
          while ((ch = input()) != '\n')
             input_line[line_indx++] = ch;
          reset_input_line();
        }
\{      { if (comment == 0) ++braces;  input_line[line_indx++] = yytext[0]; }
\}      { if (comment == 0) --braces;  input_line[line_indx++] = yytext[0]; }
\"      { if (comment == 0) {
             ch = yytext[0];
             do {
                input_line[line_indx++] = ch;
                prev_ch = ch;
             } while (!(((ch = input()) == '"') && prev_ch != '\\'));
          }
        }
\(      { if (comment == 0 && braces == 0) {
             tagline_flag = 1;
             strcpy(tag, identifer);  
          }
          input_line[line_indx++] = yytext[0];
          debug2_printf(("Matched '(' tag='%s', braces=%d, comment=%d\n", tag, braces, comment));
        }
\)      { input_line[line_indx++] = yytext[0];
          debug2_printf(("Matched ')' tag='%s', braces=%d, comment=%d\n", tag, braces, comment));
          while (comment == 0 && braces == 0 && ((ch = input()) != EOF)) {
             input_line[line_indx++] = ch;
             if (ch == '{') {
                tag_flag = 1;
                ++braces;
                break;
             } else if (ch == ';') {
                tag_flag = 0;
                break;
             } else if (ch == '\n') {
                reset_input_line();
             }
          }
        }
[a-zA-Z_][a-zA-Z0-9_]*   {
          strncpy(identifer, yytext, sizeof(identifer) - 1);
          strcat(input_line, yytext);
          line_indx += yyleng;
          debug2_printf(("ident='%s'\n", identifer));
        }
.       { input_line[line_indx++] = yytext[0]; }
\n      { reset_input_line(); }
%%


static void
reset_input_line()
{
        debug_printf(("reset_input_line() tagline_flag=%d, tag_flag=%d, tag='%s', tag_line='%s'\n", tagline_flag, tag_flag, tag, tag_line));
        if (tagline_flag)
                strcpy(tag_line, input_line);  
        if (tag_flag) {
                printf("%s\t%s\t/^%s$\n", tag, avs_filename, tag_line);
        }
        tagline_flag = tag_flag = 0;
        memset(input_line, 0, sizeof(input_line)); 
        line_indx = 0;
}


static void
avstags(char *filename, FILE *fp)
{
        avs_filename = filename;
        yyin = fp;
        yylex();
}


main(int argc, char *argv[])
{
        int indx;
        FILE *fp;

        if (argc == 1) {
                avstags("", stdin);
        } else {
                for (indx = 1; indx  tags
*/

Advertisements