-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinktype.c
More file actions
35 lines (29 loc) · 842 Bytes
/
linktype.c
File metadata and controls
35 lines (29 loc) · 842 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
* linktype.c
*
* Created on: Jul 20, 2019
* Author: mislav
*/
#include "linktype.h"
//Push all the different header link layer types and set them as globals in Lua
//Link types are loaded from a CSV, making it possible to update them easily should new link types come out (they probably will)
void setHeaderLinkTypeValues(lua_State *L) {
FILE *fp;
char linktype_name[50];
int linktype_id;
fp=fopen("linktypes.csv", "r"); //Open file
if(fp==NULL) //If it fails, return
{
printf("ERROR: Failed to read link types from linktypes.csv file!\n");
fclose(fp);
return;
}
//Read the file
while(fscanf(fp,"%[^,],%d\n",linktype_name, &linktype_id)!=EOF)
{
//Push the values to the Lua stack, then set them as named constants
lua_pushnumber(L, linktype_id);
lua_setfield(L, -2, linktype_name);
}
fclose(fp);
}