xref: /Universal-ctags/parsers/abaqus.c (revision c62be1479922a47ac46d4d6827d9fb6b78759148)
1 /*
2  *   Copyright (c) 2013, Baptiste Pierrat
3  *
4  *   This source code is released for free distribution under the terms of the
5  *   GNU General Public License version 2 or (at your opinion) any later version.
6  *
7  *   This module contains functions for generating tags for source files
8  *   for Abaqus inp files (https://en.wikipedia.org/wiki/Abaqus).
9  */
10 
11 /*
12 *   INCLUDE FILES
13 */
14 #include "general.h"	/* must always come first */
15 
16 #include <ctype.h>
17 #include <string.h>
18 
19 #include "parse.h"
20 #include "read.h"
21 #include "vstring.h"
22 #include "routines.h"
23 
24 /*
25 *   DATA DEFINITIONS
26 */
27 typedef enum {
28 	K_PART,
29 	K_ASSEMBLY,
30 	K_STEP
31 } AbaqusKind;
32 
33 static kindDefinition AbaqusKinds[] = {
34      { true, 'p', "part",     "Parts" },
35      { true, 'a', "assembly", "Assembly" },
36      { true, 's', "step",     "Steps" }
37 };
38 
39 /*
40 *   FUNCTION DEFINITIONS
41 */
42 
getWord(const char * ref,const char ** ptr)43 static int getWord(const char *ref, const char **ptr)
44 {
45 	const char *p = *ptr;
46 
47 	while ((*ref != '\0') && (*p != '\0') && (tolower(*ref) == tolower(*p))) ref++, p++;
48 
49 	if (*ref) return false;
50 
51 	*ptr = p;
52 	return true;
53 }
54 
55 
createTag(AbaqusKind kind,const char * buf)56 static void createTag(AbaqusKind kind, const char *buf)
57 {
58 	vString *name;
59 
60 	if (*buf == '\0') return;
61 
62 	buf = strstr(buf, "=");
63 	if (buf == NULL) return;
64 
65 	buf += 1;
66 
67 	if (*buf == '\0') return;
68 
69 	name = vStringNew();
70 
71 	do
72 	{
73 		vStringPut(name, (int) *buf);
74 		++buf;
75 	} while ((*buf != '\0') && (*buf != ','));
76 	makeSimpleTag(name, kind);
77 	vStringDelete(name);
78 }
79 
80 
findAbaqusTags(void)81 static void findAbaqusTags(void)
82 {
83 	const char *line;
84 
85 	while ((line = (const char*)readLineFromInputFile()) != NULL)
86 	{
87 		const char *cp = line;
88 
89 		for (; *cp != '\0'; cp++)
90 		{
91 			if (*cp == '*')
92 			{
93 				cp++;
94 
95 				/* Parts*/
96 				if (getWord("part", &cp))
97 				{
98 					createTag(K_PART, cp);
99 					continue;
100 				}
101 				/* Assembly */
102 				if (getWord("assembly", &cp))
103 				{
104 					createTag(K_ASSEMBLY, cp);
105 					continue;
106 				}
107 				/* Steps */
108 				if (getWord("step", &cp))
109 				{
110 					createTag(K_STEP, cp);
111 					continue;
112 				}
113 			}
114 		}
115 	}
116 }
117 
118 
AbaqusParser(void)119 extern parserDefinition* AbaqusParser (void)
120 {
121 	static const char *const extensions [] = { "inp", NULL };
122 	parserDefinition * def = parserNew ("Abaqus");
123 	def->kindTable  = AbaqusKinds;
124 	def->kindCount  = ARRAY_SIZE (AbaqusKinds);
125 	def->extensions = extensions;
126 	def->parser     = findAbaqusTags;
127 	return def;
128 }
129