/
PluginSensor.cpp
75 lines (65 loc) · 2.17 KB
/
PluginSensor.cpp
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* $Id$
* $URL$
*
* Copyright (C) 2003 Michael Reinelt <michael@reinelt.co.at>
* Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
* Copyright (C) 2009 Scott Sibley <scott@starlon.net>
*
* This file is part of LCDControl.
*
* LCDControl is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LCDControl is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LCDControl. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <cstring>
#include "debug.h"
#include "PluginFile.h"
#ifdef WITH_DMALLOC
#include <dmalloc.h>
#endif
using namespace LCD;
/* function 'readline' */
/* takes two arguments, file name and line number */
/* returns text of that line */
string PluginFile::Readline(string arg1, int arg2) {
char value[80], val2[80];
FILE *fp;
int reqline, i, size;
reqline = arg2;
fp = fopen(arg1.c_str(), "r");
if (!fp) {
LCDError("readline couldn't open file '%s'", arg1.c_str());
value[0] = '\0';
} else {
i = 0;
while (!feof(fp) && i++ < reqline) {
fgets(val2, sizeof(val2), fp);
size = strcspn(val2, "\r\n");
strncpy(value, val2, size);
value[size] = '\0';
/* more than 80 chars, chew up rest of line */
while (!feof(fp) && strchr(val2, '\n') == NULL) {
fgets(val2, sizeof(val2), fp);
}
}
fclose(fp);
}
return value;
}
void PluginFile::Connect(Evaluator *visitor) {
QScriptEngine *engine = visitor->GetEngine();
QScriptValue val = engine->newObject();
QScriptValue objVal = engine->newQObject(val, this);
engine->globalObject().setProperty("file", objVal);
}
Q_EXPORT_PLUGIN2(_PluginFile, PluginFile)