OpenCores
URL https://opencores.org/ocsvn/pavr/pavr/trunk

Subversion Repositories pavr

[/] [pavr/] [trunk/] [tools/] [build_vhdl_hdr/] [build_vhdl_hdr.c] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 doru
#include <string.h>
2
#include <io.h>
3
#include <stdio.h>
4
#include <stdlib.h>
5
#include <malloc.h>
6
#include "../common/tagScan.h"
7
 
8
#define TAG_FILE_HDR_BEGIN  "-- <File header>"
9
#define TAG_FILE_HDR_END    "-- </File header>"
10
#define TAG_FILE_INFO_BEGIN "-- <File info>"
11
#define TAG_FILE_INFO_END   "-- </File info>"
12
#define TAG_FILE_BODY_BEGIN "-- <File body>"
13
#define TAG_FILE_BODY_END   "-- </File body>"
14
 
15
#define TAGGED_PARAGRAPHS_SEPARATOR "\n\n\n\n"
16
 
17
 
18
 
19
int main(int argc, char * argv[]) {
20
   FILE *fStr1;
21
   scanTag_t stag;
22
   long int pos1, pos2;
23
   char *tStr1, *tStr2;
24
   char chr;
25
 
26
   if (argc > 2)
27
   {
28
      scanTag_t_construct(&stag);
29
 
30
      fStr1 = fopen(argv[2], "rb");
31
      if (fStr1 != NULL)
32
      {
33
         fseek(fStr1, 0L, SEEK_SET);
34
         pos1 = ftell(fStr1);
35
         fseek(fStr1, 0L, SEEK_END);
36
         pos2 = ftell(fStr1);
37
 
38
         // Make room for template header, 2x(CR+LF), and string terminator.
39
         tStr1 = (char *) malloc(pos2-pos1+4+2);
40
         tStr2 = (char *) malloc(1+2);
41
         strcpy(tStr1, "\n");
42
         fseek(fStr1, 0L, SEEK_SET);
43
         while (feof(fStr1) == 0)
44
         {
45
            fread(&chr, 1, 1, fStr1);
46
            if (feof(fStr1) == 0)
47
            {
48
               sprintf(tStr2, "%c", chr);
49
               strcat(tStr1, tStr2);
50
            }
51
         }
52
 
53
         // Scan VHDL source and modify the paragraph tagged by `-- <File Header>' `-- </File Header>'.
54
         scanTag_t_writeTaggedText(TAG_FILE_HDR_BEGIN, TAG_FILE_HDR_END, tStr1, argv[1], &stag);
55
         free(tStr1);
56
         free(tStr2);
57
      }
58
      else
59
      {
60
         exit(1);
61
      }
62
 
63
 
64
      fprintf(stdout, "status=%s\n", scanTag_t_getStatus(&stag));
65
      scanTag_t_destruct(&stag);
66
   }
67
   else
68
   {
69
      fprintf(stdout, "Usage: this_executable vhdl_src template_hdr\n");
70
   }
71
   return 0;
72
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.