Chameleon Applications

Chameleon Applications Svn Source Tree

Root/branches/ErmaC/ChameleonPrefPane/Sources/ShellProcess.cpp

1/*
2 * shell_process.cpp
3 *
4 * Created by Rekursor on 1/17/2010.
5 *
6 */
7
8#include "ShellProcess.h"
9#include <string.h>
10#include <sys/stat.h>
11#include "string_util.h"
12
13//----------------------------------------------------------------
14// portable open process:
15FILE * ShellProcess::open(const char *cmd, const char *mode) {
16_fpt=::popen(cmd,mode);
17return _fpt;
18}
19
20//----------------------------------------------------------------
21int ShellProcess::close() {
22int ret = ::pclose(_fpt);
23_fpt=NULL;
24return ret;
25}
26
27//----------------------------------------------------------------
28char * ShellProcess::get_line(char * line, size_t s, const char *matching)
29{
30if (_fpt==NULL || line==NULL) return NULL;
31char * l = fgets(line, s, _fpt);
32
33if (matching==NULL || (*matching)=='\0')
34return l; // we're done
35
36// search first line matching substring 'matching'
37size_t len = strlen(line);
38
39for (; l!=NULL && (len >0) ;)
40{
41if (strstr(line, matching))
42{
43return l;
44}
45
46*line = '\0';
47l = fgets(line, s, _fpt);
48len = strlen(line);
49}
50
51return l;
52}
53

Archive Download this file

Revision: 396