NetSim Source Code Help
Loading...
Searching...
No Matches
FileInput.c
Go to the documentation of this file.
1/************************************************************************************
2* Copyright (C) 2020 *
3* TETCOS, Bangalore. India *
4* *
5* Tetcos owns the intellectual property rights in the Product and its content. *
6* The copying, redistribution, reselling or publication of any or all of the *
7* Product or its content without express prior written consent of Tetcos is *
8* prohibited. Ownership and / or any other right relating to the software and all *
9* intellectual property rights therein shall remain at all times with Tetcos. *
10* *
11* Author: Shashi kant suman
12* *
13* ---------------------------------------------------------------------------------*/
14#include "main.h"
15#include "NetSim_utility.h"
16#include <signal.h>
17#include "CLI.h"
18
20
22{
23 fileClientInfo = info;
24}
25
27{
28 return fileClientInfo;
29}
30
32{
33 double time = 0;
34 NETSIM_ID dev = 0;
35
36 char input[BUFSIZ];
38 memset(&pevent, 0, sizeof pevent);
39 pevent.nEventType = TIMER_EVENT;
42 while (fgets(input, BUFSIZ, fp) != NULL)
43 {
44 char* s = input;
45 s = lskip(s);
46 if (!*s || *s == '#')
47 continue; //Empty or comment line
48
49 _strupr(s);
50
51 size_t len = strlen(s);
52 if (len > 0 && s[len - 1] == '\n') s[--len] = '\0';
53
54 if (*s == 'T')
55 {
56 char* f = strtok(s, "=");
57 if (!_stricmp(f, "time"))
58 {
59 char* l = strtok(NULL, "=\n");
60 time = atof(l)*SECOND;
61 }
62 else
63 {
64 goto CMDINPUT;
65 }
66 }
67 else if (*s == 'D')
68 {
69 char* f = strtok(s, "=");
70 if (!_stricmp(f, "device"))
71 {
72 char* l = strtok(NULL, "=\n");
74 }
75 else
76 {
77 goto CMDINPUT;
78 }
79 }
80 else
81 {
82 CMDINPUT:
83 pevent.dEventTime = time;
84 pevent.nDeviceId = dev;
85 pevent.nDeviceType = DEVICE_TYPE(dev);
88 fnpAddEvent(&pevent);
89 }
90 }
91}
92
93void write_to_file(ptrCLIENTINFO info, char* msg, int len)
94{
95 fwrite(msg, sizeof(char), len, info->CLIENT.fileClient.fpOutputFile);
96 fflush(info->CLIENT.fileClient.fpOutputFile);
97}
unsigned int NETSIM_ID
Definition: Animation.h:45
ptrCOMMANDARRAY get_commandArray(char *text)
Definition: Command.c:13
CLIHANDLE FORM_CLI_HANDLE(ptrCOMMANDARRAY cmd, ptrCLIENTINFO info)
static ptrCLIENTINFO fileClientInfo
Definition: FileInput.c:19
void write_to_file(ptrCLIENTINFO info, char *msg, int len)
Definition: FileInput.c:93
void read_file_and_execute(FILE *fp)
Definition: FileInput.c:31
void set_fileClientInfo(ptrCLIENTINFO info)
Definition: FileInput.c:21
ptrCLIENTINFO get_fileClientInfo()
Definition: FileInput.c:26
char * _strupr(char *s)
#define _stricmp
Definition: Linux.h:127
char * lskip(const char *s)
@ SUBEVENT_EXECUTECOMMAND
Definition: Stack.h:127
NETSIM_ID fn_NetSim_Stack_GetDeviceId_asName(const char *name)
#define DEVICE_TYPE(DeviceId)
Definition: Stack.h:773
#define SECOND
Definition: Stack.h:60
@ TIMER_EVENT
Definition: Stack.h:114
#define PROTOCOL_CLI
Definition: Stack.h:146
uint f(uint state, uchar key[])
Definition: des.c:172
#define fnpAddEvent(pstruEvent)
Definition: main.h:191
EVENT_TYPE nEventType
Definition: Stack.h:747
NETSIM_ID nProtocolId
Definition: Stack.h:748
NETSIM_ID nSubEventType
Definition: Stack.h:757
NETSIM_ID nDeviceId
Definition: Stack.h:750
netsimDEVICE_TYPE nDeviceType
Definition: Stack.h:749
union stru_clientInfo::client CLIENT
FILE * fpOutputFile
Definition: CLI.h:47
FILECLIENTINFO fileClient
Definition: CLI.h:75