本文整理汇总了C++中popen函数的典型用法代码示例。如果您正苦于以下问题:C++ popen函数的具体用法?C++ popen怎么用?C++ popen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了popen函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: LOG_PRINT
void alarms_history::on_pushButtonSave_clicked()
{
/* Check USB key */
if (USBCheck())
{
if (USBmount() == false)
{
LOG_PRINT(error_e, "Cannot mount the usb key\n");
QMessageBox::critical(this,tr("USB error"), tr("Cannot mount the usb key"));
return;
}
char srcfilename [MAX_LINE] = "";
char dstfilename [MAX_LINE] = "";
/* compose the source file name ans the destination file name */
sprintf(srcfilename, "%s/%s", ALARMS_DIR, logFileList.at(_current).toAscii().data());
sprintf(dstfilename, "%s/%s_%s",
usb_mnt_point,
QDateTime::currentDateTime().toString("yy_MM_dd_hh_mm_ss").toAscii().data(),
logFileList.at(_current).toAscii().data());
/* prepare the alarm filtered file */
/* open the source alarm file */
FILE * fp = fopen(srcfilename, "r");
if (fp == NULL)
{
LOG_PRINT(error_e, "Cannot open '%s'\n", srcfilename);
QMessageBox::critical(this,tr("USB error"), tr("Cannot open the alarm file '%1'").arg(srcfilename));
return;
}
/* open the dest alarm file */
FILE * fpout = fopen(dstfilename, "w");
if (fpout == NULL)
{
LOG_PRINT(error_e, "Cannot open '%s'\n", dstfilename);
QMessageBox::critical(this,tr("USB error"), tr("Cannot write the alarm file '%1'").arg(srcfilename));
return;
}
char line[LINE_SIZE];
char * p;
/* read from source and filter the level an the type of alarm and dump the dest alarm file */
while (fgets(line, LINE_SIZE, fp) != NULL)
{
/* type;level;tag;event;YYYY/MM/DD,HH:mm:ss;description */
/* type */
p = strtok(line, ";");
if (p == NULL)
{
LOG_PRINT(info_e, "Skip empty line'%s'\n", line);
continue;
}
/* skip the alarms */
if (atoi(p) == ALARM && _alarm == false)
{
LOG_PRINT(info_e, "Skip alarm '%s'\n", line);
continue;
}
/* skip the events */
if (atoi(p) == EVENT && _event == false)
{
LOG_PRINT(info_e, "Skip event '%s'\n", line);
continue;
}
/* level */
p = strtok(NULL, ";");
if (p == NULL)
{
LOG_PRINT(error_e, "Malformed log file [%s]\n", line);
return;
}
/* skip the level */
if (atoi(p) < _level)
{
LOG_PRINT(info_e, "Skip level '%d %d'\n", atoi(p), _level);
continue;
}
fprintf(fpout, "%s", line);
}
fclose(fp);
fclose(fpout);
/* create the signature file */
/* Open the command for reading. */
sprintf(line, "%s %s", APP_SIGN, dstfilename);
fp = popen(line, "r");
if (fp == NULL) {
LOG_PRINT(error_e,"Failed to run command '%s'\n", line );
return;
}
char sign[LINE_SIZE];
/* Read the output a line at a time - output it. */
if (fscanf(fp, "%s", sign) > 0) {
LOG_PRINT(info_e,"SIGN: '%s'\n", sign);
}
//.........这里部分代码省略.........
开发者ID:MECTsrl,项目名称:mect_apps,代码行数:101,代码来源:alarms_history.cpp
示例2: strlen
FILE *fopen_comp (char *file, char *mode, int32 *ispipe)
{
char command[16384];
FILE *fp;
int32 k, isgz;
k = strlen (file);
#if (WIN32)
*ispipe = (k > 3) &&
((strcmp (file+k-3, ".gz") == 0) || (strcmp (file+k-3, ".GZ") == 0));
isgz = *ispipe;
#else
*ispipe = 0;
isgz = 0;
if ((k > 2) && ((strcmp (file+k-2, ".Z") == 0) || (strcmp (file+k-2, ".z") == 0))) {
*ispipe = 1;
} else {
if ((k > 3) &&
((strcmp (file+k-3, ".gz") == 0) || (strcmp (file+k-3, ".GZ") == 0))) {
*ispipe = 1;
isgz = 1;
}
}
#endif
if (*ispipe) {
#if (WIN32)
if (strcmp (mode, "r") == 0) {
sprintf (command, "gzip.exe -d -c %s", file);
if ((fp = _popen (command, mode)) == NULL) {
E_ERROR_SYSTEM("_popen (%s,%s) failed\n", command, mode);
return NULL;
}
} else {
E_ERROR ("fopen_comp not implemented for mode = %s\n", mode);
return NULL;
}
#else
if (strcmp (mode, "r") == 0) {
if (isgz)
sprintf (command, "gunzip -c %s", file);
else
sprintf (command, "zcat %s", file);
if ((fp = popen (command, mode)) == NULL) {
E_ERROR_SYSTEM("popen (%s,%s) failed\n", command, mode);
return NULL;
}
} else if (strcmp (mode, "w") == 0) {
if (isgz)
sprintf (command, "gzip > %s", file);
else
sprintf (command, "compress -c > %s", file);
if ((fp = popen (command, mode)) == NULL) {
E_ERROR_SYSTEM("popen (%s,%s) failed\n", command, mode);
return NULL;
}
} else {
E_ERROR ("fopen_comp not implemented for mode = %s\n", mode);
return NULL;
}
#endif
} else {
fp = fopen (file, mode);
}
return (fp);
}
开发者ID:10v,项目名称:cmusphinx,代码行数:70,代码来源:io.c
示例3: ExportCL
bool ExportCL(AudacityProject *project, bool stereo, wxString fName,
bool selectionOnly, double t0, double t1, MixerSpec *mixerSpec)
{
int rate = int(project->GetRate() + 0.5);
wxWindow *parent = project;
TrackList *tracks = project->GetTracks();
wxString command = gPrefs->Read(wxT("/FileFormats/ExternalProgramExportCommand"), wxT("lame - '%f'"));
command.Replace(wxT("%f"), fName);
/* establish parameters */
int channels = stereo ? 2 : 1;
unsigned long totalSamples = (unsigned long)((t1 - t0) * rate + 0.5);
unsigned long sampleBytes = totalSamples * channels * SAMPLE_SIZE(int16Sample);
/* fill up the wav header */
wav_header header;
header.riffID[0] = 'R';
header.riffID[1] = 'I';
header.riffID[2] = 'F';
header.riffID[3] = 'F';
header.riffType[0] = 'W';
header.riffType[1] = 'A';
header.riffType[2] = 'V';
header.riffType[3] = 'E';
header.lenAfterRiff = sampleBytes + 32;
header.fmtID[0] = 'f';
header.fmtID[1] = 'm';
header.fmtID[2] = 't';
header.fmtID[3] = ' ';
header.formatChunkLen = 16;
header.formatTag = 1;
header.channels = channels;
header.sampleRate = rate;
header.bitsPerSample = SAMPLE_SIZE(int16Sample) * 8;
header.blockAlign = header.bitsPerSample * header.channels;
header.avgBytesPerSec = header.sampleRate * header.blockAlign;
header.dataID[0] = 'd';
header.dataID[1] = 'a';
header.dataID[2] = 't';
header.dataID[3] = 'a';
header.dataLen = sampleBytes;
FILE *pipe = popen(OSFILENAME(command), "w");
/* write the header */
fwrite( &header, sizeof(wav_header), 1, pipe );
sampleCount maxBlockLen = 44100 * 5;
bool cancelling = false;
int numWaveTracks;
WaveTrack **waveTracks;
tracks->GetWaveTracks(selectionOnly, &numWaveTracks, &waveTracks);
Mixer *mixer = new Mixer(numWaveTracks, waveTracks,
tracks->GetTimeTrack(),
t0, t1,
channels, maxBlockLen, true,
rate, int16Sample, true, mixerSpec);
GetActiveProject()->ProgressShow(_("Export"),
selectionOnly ?
_("Exporting the selected audio using command-line encoder") :
_("Exporting the entire project using command-line encoder"));
while(!cancelling) {
sampleCount numSamples = mixer->Process(maxBlockLen);
if (numSamples == 0)
break;
samplePtr mixed = mixer->GetBuffer();
char *buffer = new char[numSamples * SAMPLE_SIZE(int16Sample) * channels];
wxASSERT(buffer);
// Byte-swapping is neccesary on big-endian machines, since
// WAV files are little-endian
#if wxBYTE_ORDER == wxBIG_ENDIAN
{
short *buffer = (short*)mixed;
for( int i = 0; i < numSamples; i++ )
buffer[i] = wxINT16_SWAP_ON_BE(buffer[i]);
}
#endif
fwrite( mixed, numSamples * channels * SAMPLE_SIZE(int16Sample), 1, pipe );
int progressvalue = int (1000 * ((mixer->MixGetCurrentTime()-t0) /
(t1-t0)));
cancelling = !GetActiveProject()->ProgressUpdate(progressvalue);
delete[]buffer;
}
GetActiveProject()->ProgressHide();
//.........这里部分代码省略.........
开发者ID:andreipaga,项目名称:audacity,代码行数:101,代码来源:ExportCL.cpp
示例4: main
//.........这里部分代码省略.........
printf("OK: %s\n", strerror(errno));
else
printf("BUG: Did not fail.\n");
show_prompt("mount('/', '/', 'nonexistentfs') ", 1);
if (mount("/", "/", "nonexistentfs", 0, NULL))
printf("OK: %s\n", strerror(errno));
else
printf("BUG: Did not fail.\n");
set_profile(0, "file::mount");
}
mkdir("/tmp/mount/", 0755);
mkdir("/tmp/mount_bind/", 0755);
mkdir("/tmp/mount_move/", 0755);
/* Test mount(). */
{
static char buf[4096];
char *dev_ram_path = canonicalize_file_name("/dev/ram0");
if (!dev_ram_path)
dev_ram_path = canonicalize_file_name("/dev/ram");
if (!dev_ram_path) {
dev_ram_path = "/dev/ram0";
mknod(dev_ram_path, S_IFBLK, MKDEV(1, 0));
}
memset(buf, 0, sizeof(buf));
{
struct stat sbuf;
FILE *fp = NULL;
snprintf(buf, sizeof(buf) - 1, "zcat - > %s",
dev_ram_path);
if (lstat(dev_ram_path, &sbuf) == 0 &&
S_ISBLK(sbuf.st_mode) && MAJOR(sbuf.st_rdev) == 1)
fp = popen(buf, "w");
if (fp) {
if (fwrite(compressed_ext2_image_sample, 1,
sizeof(compressed_ext2_image_sample), fp) !=
sizeof(compressed_ext2_image_sample))
err(1, "fwrite");
pclose(fp);
} else
fprintf(stderr, "Can't write to %s .\n",
dev_ram_path);
}
set_profile(3, "file::mount");
/* Test standard case */
show_prompt("mount('none', '/tmp/mount/', 'tmpfs') for "
"'/tmp/mount/'", 1);
if (mount("none", "/tmp/mount/", "tmpfs", 0, NULL) == EOF &&
errno == EPERM)
printf("OK: Permission denied.\n");
else
printf("BUG: %s\n", strerror(errno));
/* Test device_name with pattern */
snprintf(buf, sizeof(buf) - 1, "mount('%s', '/tmp/mount/', "
"'ext2') for '%s\\*'", dev_ram_path, dev_ram_path);
show_prompt(buf, 1);
if (mount(dev_ram_path, "/tmp/mount/", "ext2", MS_RDONLY, NULL)
== EOF && errno == EPERM)
printf("OK: Permission denied.\n");
else
printf("BUG: %s\n", strerror(errno));
/* Test dir_name with pattern */
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:67,代码来源:tomoyo_filesystem_test.c
示例5: install_filter
static inline int
install_filter(char * intf, char * filter_text) {
FILE *fp;
int status;
char fil[40];
char cmd[1035];
struct sock_filter * FILTER;
int filter_len;
//sprintf(cmd, "tcpdump -dd -i %s %s", intf, filter_text);
sprintf(cmd, "tcpdump -ddd -i %s %s", intf, filter_text);
printf("cmd: %s\n", cmd);
/* Open the command for reading. */
fp = popen(cmd, "r");
if (fp == NULL) {
printf("Failed to run command\n" );
exit;
}
/* Read the output a line at a time - output it. */
fgets(fil, sizeof(fil)-1, fp);
filter_len = atoi(fil);
//printf("len: %d\n", filter_len);
FILTER = (struct sock_filter *)(malloc(sizeof(struct sock_filter) * filter_len));
//while (fgets(fil, sizeof(fil)-1, fp) != NULL) {
int i = 0;
for (i = 0; i < filter_len; i++) {
struct sock_filter * filter_line = &FILTER[i];
int n;
char del = ' ';
if (fgets(fil, sizeof(fil)-1, fp) == NULL) {
printf("Error creating filter\n");
exit(0);
}
//printf("%s", fil);
n = atoi(strtok(fil, &del));
//printf("val=%d ", n);
filter_line->code = (unsigned short)n;
n = atoi(strtok(NULL, &del));
//printf("val=%d ", n);
filter_line->jt = (unsigned char)n;
n = atoi(strtok(NULL, &del));
//printf("val=%d ", n);
filter_line->jf = (unsigned char)n;
n = atoi(strtok(NULL, &del));
//printf("val=%d ", n);
filter_line->k = (unsigned int)n;
//printf("\n");
}
printf("created filter structure\n");
/* close */
pclose(fp);
return 0;
}
开发者ID:yiannisy,项目名称:behop-misc,代码行数:67,代码来源:test.c
示例6: makecommonpart
/**
* makecommonpart: make a common part for "mains.html" and "index.html"
*
* @param[in] title
* @param[in] defines
* @param[in] files
* @return index common part
*/
static char *
makecommonpart(const char *title, const char *defines, const char *files)
{
FILE *ip;
STRBUF *sb = strbuf_open(0);
STRBUF *ib = strbuf_open(0);
char buf[MAXFILLEN];
const char *tips = "Go to the GLOBAL project page.";
const char *_, *item;
strbuf_puts(sb, title_begin);
strbuf_puts(sb, title);
strbuf_puts_nl(sb, title_end);
strbuf_puts_nl(sb, poweredby_begin);
strbuf_sprintf(sb, "Last updated %s%s\n", now(), br);
if (Iflag) {
snprintf(buf, sizeof(buf), "Powered by GLOBAL-%s.", get_version());
strbuf_puts(sb, gen_href_begin_with_title_target(NULL, www, NULL, NULL, tips,"_top"));
strbuf_puts(sb, gen_image(CURRENT, "pglobe", buf));
strbuf_puts(sb, gen_href_end());
strbuf_puts(sb, br);
} else {
strbuf_sprintf(sb, "Powered by %sGLOBAL-%s%s.%s\n",
gen_href_begin_with_title_target(NULL, www, NULL, NULL, tips, "_top"),
get_version(),
gen_href_end(),
br);
}
strbuf_puts_nl(sb, poweredby_end);
strbuf_puts_nl(sb, hr);
/*
* Print items according to the value of variable 'item_order'.
*/
for (item = item_order; *item; item++) {
switch (*item) {
case 'c':
if (caution) {
strbuf_puts_nl(sb, caution_begin);
strbuf_sprintf(sb, "<font size='+2' color='red'>CAUTION</font>%s\n", br);
strbuf_sprintf(sb, "This hypertext consists of %d files.\n", html_count);
strbuf_puts_nl(sb, "Please don't download the whole hypertext using a hypertext copy tool.");
strbuf_puts_nl(sb, "Our network cannot afford such traffic.");
strbuf_puts_nl(sb, "Instead, you can generate the same thing in your computer using");
strbuf_puts(sb, gen_href_begin_with_title_target(NULL, www, NULL, NULL, NULL, "_top"));
strbuf_puts(sb, "GLOBAL source code tag system");
strbuf_puts_nl(sb, gen_href_end());
strbuf_puts_nl(sb, "Thank you.");
strbuf_puts_nl(sb, caution_end);
strbuf_sprintf(sb, "\n%s\n", hr);
}
break;
case 's':
if (fflag) {
strbuf_puts(sb, makesearchpart(NULL));
strbuf_puts_nl(sb, hr);
}
break;
case 't':
if (call_file || callee_file) {
strbuf_puts(sb, header_begin);
if (call_file) {
strbuf_puts(sb, gen_href_begin(NULL, "call", normal_suffix, NULL));
strbuf_puts(sb, title_call_tree);
strbuf_puts(sb, gen_href_end());
}
if (call_file && callee_file)
strbuf_puts(sb, " / ");
if (callee_file) {
strbuf_puts(sb, gen_href_begin(NULL, "callee", normal_suffix, NULL));
strbuf_puts(sb, title_callee_tree);
strbuf_puts(sb, gen_href_end());
}
strbuf_puts_nl(sb, header_end);
strbuf_puts_nl(sb, hr);
}
break;
case 'm':
strbuf_sprintf(sb, "%sMAINS%s\n", header_begin, header_end);
snprintf(buf, sizeof(buf), PQUOTE "%s --result=ctags-xid --encode-path=\" \t\" --nofilter=path %s" PQUOTE, quote_shell(global_path), main_func);
ip = popen(buf, "r");
if (!ip)
die("cannot execute '%s'.", buf);
strbuf_puts_nl(sb, gen_list_begin());
while ((_ = strbuf_fgets(ib, ip, STRBUF_NOCRLF)) != NULL) {
char fid[MAXFIDLEN];
const char *ctags_x = parse_xid(_, fid, NULL);
strbuf_puts_nl(sb, gen_list_body(SRCS, ctags_x, fid));
}
strbuf_puts_nl(sb, gen_list_end());
if (pclose(ip) != 0)
//.........这里部分代码省略.........
开发者ID:luchachen,项目名称:global,代码行数:101,代码来源:htags.c
示例7: main
//.........这里部分代码省略.........
error = 0;
switch(message) {
case STOP_ACQUISITION:
sysinfo.acq = 0;
SendMessage(client_message[SPIKE_MAIN].fd, ACQUISITION_STOPPED,
NULL, 0);
break;
case START_ACQUISITION:
sysinfo.acq = 1;
SendMessage(client_message[SPIKE_MAIN].fd, ACQUISITION_STARTED,
NULL, 0);
break;
case START_SAVE:
sysinfo.diskon = 1;
SendMessage(client_message[SPIKE_MAIN].fd,
SAVE_STARTED, NULL, 0);
break;
case STOP_SAVE:
sysinfo.diskon = 0;
SendMessage(client_message[SPIKE_MAIN].fd,
SAVE_STOPPED, NULL, 0);
break;
case OPEN_FILE:
/* we can get this message in the middle of saving
* data if the main program has determined that the
* current file size is too large, so we need to
* close the current file if it is open */
if (outfile != NULL) gzclose(outfile);
ofm = (OpenFileMessage *) messagedata;
/* we will have already checked to make sure that the
* file can be opened */
/* make sure the file name is correctly terminated */
strncpy(sysinfo.datafilename, ofm->filename,
sizeof(sysinfo.datafilename));
sysinfo.datafilename[sizeof(sysinfo.datafilename)-1] = '\0';
if (ofm->type != OpenFileMessage::GZip) {
sprintf(tmpstring, "file type is not GZip, but rather was: %d; defaulting to GZip!\n", (int)ofm->type);
StatusMessage(tmpstring, client_message);
}
// build string to pass to gzopen specifying open more,
// compression level, etc
snprintf(tmpstring, sizeof(tmpstring), "ab%u",
ofm->compression_level);
sysinfo.use_compression = ofm->compression_level ?
true : false;
sysinfo.compression_level = ofm->compression_level;
outfile = gzopen(sysinfo.datafilename, tmpstring);
if( Z_NULL == outfile) {
fprintf(STATUSFILE, "gzopen() failed to open file: %s with options %s\n", sysinfo.datafilename, tmpstring);
}
else{
fprintf(STATUSFILE, "gzopen() opened file: %s with options %s\n", sysinfo.datafilename, tmpstring);
sysinfo.fileopen = 1;
}
snprintf(tmpstring, sizeof(tmpstring), "df %s\n",
sysinfo.datafilename);
diskfree = 0;
if ((pipe = popen(tmpstring, "r")) == NULL) {
sprintf(tmpstring, "Error opening pipe to check disk usage");
StatusMessage(tmpstring, client_message);
}
else {
fgets(tmpstring, TMPSTRINGLEN, pipe);
fscanf(pipe, "%s%d%d%d", tmpstring, &tmp1, &tmp2, &diskfree);
}
/* convert KB to MB for diskfree */
diskfree /= 1024;
pclose(pipe);
SendMessage(client_message[SPIKE_MAIN].fd, FILE_OPENED,
(char *) &diskfree, sizeof(int));
break;
case CLOSE_FILE:
closefile = 1;
break;
case SYSTEM_INFO:
/* we don't need any systeminfo information in this
* module */
break;
case EXIT:
saveexit(0);
break;
default:
break;
}
}
id++;
}
/* close the file only if no new data came in on the last iteration of the for loop */
if (closefile && !newdata) {
gzclose(outfile);
outfile = NULL;
sysinfo.fileopen = 0;
SendMessage(client_message[SPIKE_MAIN].fd, FILE_CLOSED, NULL, 0);
closefile = 0;
}
}
return 0;
}
开发者ID:kemerelab,项目名称:NSpike2,代码行数:101,代码来源:spike_save_data.cpp
示例8: parse_netstat
/**
* Default implementation to get the default gateway by parsing the
* output of the "netstat -rn" command.
*
* @param addrp where gateway address is to be written
*
* @return 0 on success, -1 on failure with errno set.
*/
static G_GNUC_COLD int
parse_netstat(host_addr_t *addrp)
#ifdef HAS_POPEN
{
FILE *f = NULL;
char tmp[80];
guint32 gate = 0;
/*
* This implementation should be a safe default on UNIX platforms, but
* it is inefficient and as such can only constitute a fallback.
*/
if (-1 != access("/bin/netstat", X_OK)) {
f = popen("/bin/netstat -rn", "r");
} else if (-1 != access("/usr/bin/netstat", X_OK)) {
f = popen("/usr/bin/netstat -rn", "r");
}
if (NULL == f) {
errno = ENOENT; /* netstat not found */
return -1;
}
/*
* Typical netstat -rn output:
*
* Destination Gateway Flags .....
* 0.0.0.0 192.168.0.200 UG
* default 192.168.0.200 UG
*
* Some systems like linux display "0.0.0.0", but traditional UNIX
* output is "default" for the default route.
*/
while (fgets(tmp, sizeof tmp, f)) {
char *p;
guint32 ip;
p = is_strprefix(tmp, "default");
if (NULL == p)
p = is_strprefix(tmp, "0.0.0.0");
if (NULL == p || !is_ascii_space(*p))
continue;
ip = string_to_ip(p);
if (ip != 0) {
gate = ip;
break;
}
}
pclose(f);
if (0 == gate) {
errno = ENETUNREACH;
return -1;
}
*addrp = host_addr_get_ipv4(gate);
return 0;
}
开发者ID:Haxe,项目名称:gtk-gnutella,代码行数:71,代码来源:getgateway.c
示例9: main
//.........这里部分代码省略.........
arg_Source);
exit(-1);
}
arg_Text = calloc(1,file_Stat.st_size+1);
if (arg_Text != NULL)
{
if (fread(arg_Text,file_Stat.st_size,1,file_Fs) != 1)
{
fprintf(stderr,"%s: Could not read '%s'\n",
progname,arg_Source);
exit(-1);
}
}
fclose(file_Fs);
}
else
{
arg_Source = get_string_resource(dpy, XSUBLIM_ARG_PROGRAM,
"Executable");
if (arg_Source != NULL)
{
char* exe_Command = calloc(1,strlen(arg_Source)+10);
FILE* exe_Fs;
if (exe_Command == NULL)
{
fprintf(stderr,
"%s: Could not allocate space for '%s'\n",
progname,arg_Source);
exit(-1);
}
sprintf(exe_Command,"( %s ) 2>&1",arg_Source);
exe_Fs = popen(exe_Command,"r");
if (exe_Fs == NULL)
{
fprintf(stderr,"%s: Could not run '%s'\n",
progname,arg_Source);
exit(-1);
}
arg_Text = calloc(1,XSUBLIM_PROGRAM_SIZE);
if (arg_Text != NULL)
{
if (fread(arg_Text,1,XSUBLIM_PROGRAM_SIZE,
exe_Fs) <= 0)
{
fprintf(stderr,
"%s: Could not read output of '%s'\n",
progname,arg_Source);
exit(-1);
}
if (
strstr(arg_Text,": not found") ||
strstr(arg_Text,": Not found") ||
strstr(arg_Text,": command not found") ||
strstr(arg_Text,": Command not found"))
{
fprintf(stderr,
"%s: Could not find '%s'\n",
progname,arg_Source);
exit(-1);
}
}
fclose(exe_Fs);
}
else
开发者ID:MaddTheSane,项目名称:xscreensaver,代码行数:67,代码来源:xsublim.c
示例10: WritePipe
/* ---------------------------------------------------------------------------
* writes to pipe using the command defined by Settings.SaveCommand
* %f are replaced by the passed filename
*/
static int
WritePipe (char *Filename, bool thePcb)
{
FILE *fp;
int result;
char *p;
static DynamicStringType command;
int used_popen = 0;
if (EMPTY_STRING_P (Settings.SaveCommand))
{
fp = fopen (Filename, "w");
if (fp == 0)
{
Message ("Unable to write to file %s\n", Filename);
return STATUS_ERROR;
}
}
else
{
used_popen = 1;
/* setup commandline */
DSClearString (&command);
for (p = Settings.SaveCommand; *p; p++)
{
/* copy character if not special or add string to command */
if (!(*p == '%' && *(p + 1) == 'f'))
DSAddCharacter (&command, *p);
else
{
DSAddString (&command, Filename);
/* skip the character */
p++;
}
}
DSAddCharacter (&command, '\0');
printf ("write to pipe \"%s\"\n", command.Data);
if ((fp = popen (command.Data, "w")) == NULL)
{
PopenErrorMessage (command.Data);
return (STATUS_ERROR);
}
}
if (thePcb)
{
if (PCB->is_footprint)
{
WriteElementData (fp, PCB->Data);
result = 0;
}
else
result = WritePCB (fp);
}
else
result = WriteBuffer (fp);
if (used_popen)
return (pclose (fp) ? STATUS_ERROR : result);
return (fclose (fp) ? STATUS_ERROR : result);
}
开发者ID:mirage335,项目名称:pcb,代码行数:65,代码来源:file.c
示例11: address_to_line
bool address_to_line(void* call_addr, char* buffer, size_t size_of_buffer)
{
if(!call_addr) return false;
char buff[1024];
ssize_t len;
if(!get_self_path(buff,sizeof(buff),len)) return false;
const char addr2line_cmd[] = "addr2line -e";
const char postfix_cmd[] = "";
// convert address to char array
char addr[32];
sprintf(addr,"%p",call_addr);
size_t addr_len = strlen(addr);
addr[addr_len] = '\0';
// allocate memory for command
char* cmd = (char*)(malloc)(sizeof(addr2line_cmd) // command length + NULL termination
+ len // main path
+ sizeof(postfix_cmd) // postfix length + extra space
+ addr_len); // address length
// make command
strcpy(cmd,addr2line_cmd);
strcat(cmd+sizeof(addr2line_cmd)-1,buff);
sprintf(cmd+strlen(cmd)," %s",addr);
strcat(cmd,postfix_cmd);
size_t cmd_len = strlen(cmd);
cmd[cmd_len]='\0';
// run command
FILE* fp = popen(cmd,"r");
if(fp)
{
//char buffer[1024];
if(fgets(buffer, size_of_buffer, fp)!=NULL)
{
if(buffer[0] == '?')
{
size_t buffer_len = strlen(buffer);
buffer[buffer_len-1] = '\0';
pclose(fp);
free(cmd);
return false;
}
}
else
{
size_t buffer_len = strlen(buffer);
buffer[buffer_len-1] = '\0';
pclose(fp);
free(cmd);
return false;
}
}
size_t buffer_len = strlen(buffer);
buffer[buffer_len-1] = '\0';
pclose(fp);
free(cmd);
return true;
}
开发者ID:IanHG,项目名称:libmda,代码行数:63,代码来源:output_call_addr.cpp
示例12: ReadNetlist
int
ReadNetlist (char *filename)
{
static char *command = NULL;
char inputline[MAX_NETLIST_LINE_LENGTH + 1];
char temp[MAX_NETLIST_LINE_LENGTH + 1];
FILE *fp;
LibraryMenuType *menu = NULL;
LibraryEntryType *entry;
int i, j, lines, kind;
bool continued;
bool used_popen = false;
int retval = 0;
if (!filename)
return 1; /* nothing to do */
Message (_("Importing PCB netlist %s\n"), filename);
if (EMPTY_STRING_P (Settings.RatCommand))
{
fp = fopen (filename, "r");
if (!fp)
{
Message("Cannot open %s for reading", filename);
return 1;
}
}
else
{
used_popen = true;
free (command);
command = EvaluateFilename (Settings.RatCommand,
Settings.RatPath, filename, NULL);
/* open pipe to stdout of command */
if (*command == '\0' || (fp = popen (command, "r")) == NULL)
{
PopenErrorMessage (command);
return 1;
}
}
lines = 0;
/* kind = 0 is net name
* kind = 1 is route style name
* kind = 2 is connection
*/
kind = 0;
while (fgets (inputline, MAX_NETLIST_LINE_LENGTH, fp))
{
size_t len = strlen (inputline);
/* check for maximum length line */
if (len)
{
if (inputline[--len] != '\n')
Message (_("Line length (%i) exceeded in netlist file.\n"
"additional characters will be ignored.\n"),
MAX_NETLIST_LINE_LENGTH);
else
inputline[len] = '\0';
}
continued = (inputline[len - 1] == '\\') ? true : false;
if (continued)
inputline[len - 1] = '\0';
lines++;
i = 0;
while (inputline[i] != '\0')
{
j = 0;
/* skip leading blanks */
while (inputline[i] != '\0' && BLANK (inputline[i]))
i++;
if (kind == 0)
{
/* add two spaces for included/unincluded */
temp[j++] = ' ';
temp[j++] = ' ';
}
while (!BLANK (inputline[i]))
temp[j++] = inputline[i++];
temp[j] = '\0';
while (inputline[i] != '\0' && BLANK (inputline[i]))
i++;
if (kind == 0)
{
menu = GetLibraryMenuMemory (&PCB->NetlistLib);
menu->Name = strdup (temp);
menu->flag = 1;
kind++;
}
else
{
if (kind == 1 && strchr (temp, '-') == NULL)
{
kind++;
menu->Style = strdup (temp);
}
else
{
entry = GetLibraryEntryMemory (menu);
//.........这里部分代码省略.........
开发者ID:mirage335,项目名称:pcb,代码行数:101,代码来源:file.c
示例13: ReadLibraryContents
/* ---------------------------------------------------------------------------
* Read contents of the library description file (for M4)
* and then read in M4 libs. Then call a fcn to read the newlib
* footprints.
*/
int
ReadLibraryContents (void)
{
static char *command = NULL;
char inputline[MAX_LIBRARY_LINE_LENGTH + 1];
FILE *resultFP = NULL;
LibraryMenuType *menu = NULL;
LibraryEntryType *entry;
/* If we don't have a command to execute to find the library contents,
* skip this. This is used by default on Windows builds (set in main.c),
* as we can't normally run shell scripts or expect to have m4 present.
*/
if (Settings.LibraryContentsCommand != NULL &&
Settings.LibraryContentsCommand[0] != '\0')
{
/* First load the M4 stuff. The variable Settings.LibraryPath
* points to it.
*/
free (command);
command = EvaluateFilename (Settings.LibraryContentsCommand,
Settings.LibraryPath, Settings.LibraryFilename,
NULL);
#ifdef DEBUG
printf("In ReadLibraryContents, about to execute command %s\n", command);
#endif
/* This uses a pipe to execute a shell script which provides the names of
* all M4 libs and footprints. The results are placed in resultFP.
*/
if (command && *command && (resultFP = popen (command, "r")) == NULL)
{
PopenErrorMessage (command);
}
/* the M4 library contents are separated by colons;
* template : package : name : description
*/
while (resultFP != NULL && fgets (inputline, MAX_LIBRARY_LINE_LENGTH, resultFP))
{
size_t len = strlen (inputline);
/* check for maximum linelength */
if (len)
{
len--;
if (inputline[len] != '\n')
Message
("linelength (%i) exceeded; following characters will be ignored\n",
MAX_LIBRARY_LINE_LENGTH);
else
inputline[len] = '\0';
}
/* if the line defines a menu */
if (!strncmp (inputline, "TYPE=", 5))
{
menu = GetLibraryMenuMemory (&Library);
menu->Name = strdup (UNKNOWN (&inputline[5]));
menu->directory = strdup (Settings.LibraryFilename);
}
else
{
/* allocate a new menu entry if not already done */
if (!menu)
{
menu = GetLibraryMenuMemory (&Library);
menu->Name = strdup (UNKNOWN ((char *) NULL));
menu->directory = strdup (Settings.LibraryFilename);
}
entry = GetLibraryEntryMemory (menu);
entry->AllocatedMemory = strdup (inputline);
/* now break the line into pieces separated by colons */
if ((entry->Template = strtok (entry->AllocatedMemory, ":")) !=
NULL)
if ((entry->Package = strtok (NULL, ":")) != NULL)
if ((entry->Value = strtok (NULL, ":")) != NULL)
entry->Description = strtok (NULL, ":");
/* create the list entry */
len = strlen (EMPTY (entry->Value)) +
strlen (EMPTY (entry->Description)) + 4;
entry->ListEntry = (char *)calloc (len, sizeof (char));
sprintf (entry->ListEntry,
"%s, %s", EMPTY (entry->Value),
EMPTY (entry->Description));
}
}
if (resultFP != NULL)
pclose (resultFP);
}
/* Now after reading in the M4 libs, call a function to
//.........这里部分代码省略.........
开发者ID:mirage335,项目名称:pcb,代码行数:101,代码来源:file.c
示例14: PQprint
//.........这里部分代码省略.........
if (po->pager && fout == stdout && isatty(fileno(stdin)) &&
isatty(fileno(stdout)))
{
/*
* If we think there'll be more than one screen of output, try to
* pipe to the pager program.
*/
#ifdef TIOCGWINSZ
if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1 ||
screen_size.ws_col == 0 ||
screen_size.ws_row == 0)
{
screen_size.ws_row = 24;
screen_size.ws_col = 80;
}
#else
screen_size.ws_row = 24;
screen_size.ws_col = 80;
#endif
pagerenv = getenv("PAGER");
if (pagerenv != NULL &&
pagerenv[0] != '\0' &&
!po->html3 &&
((po->expanded &&
nTups * (nFields + 1) >= screen_size.ws_row) ||
(!po->expanded &&
nTups * (total_line_length / screen_size.ws_col + 1) *
(1 + (po->standard != 0)) >= screen_size.ws_row -
(po->header != 0) *
(total_line_length / screen_size.ws_col + 1) * 2
- (po->header != 0) * 2 /* row count and newline */
)))
{
fout = popen(pagerenv, "w");
if (fout)
{
usePipe = 1;
#ifndef WIN32
#ifdef ENABLE_THREAD_SAFETY
if (pq_block_sigpipe(&osigset, &sigpipe_pending) == 0)
sigpipe_masked = true;
#else
oldsigpipehandler = pqsignal(SIGPIPE, SIG_IGN);
#endif /* ENABLE_THREAD_SAFETY */
#endif /* WIN32 */
}
else
fout = stdout;
}
}
if (!po->expanded && (po->align || po->html3))
{
if (!(fields = (char **) calloc(nFields * (nTups + 1), sizeof(char *))))
{
fprintf(stderr, libpq_gettext("out of memory\n"));
abort();
}
}
else if (po->header && !po->html3)
{
if (po->expanded)
{
if (po->align)
fprintf(fout, libpq_gettext("%-*s%s Value\n"),
fieldMaxLen - fs_len, libpq_gettext("Field"), po->fieldSep);
开发者ID:42penguins,项目名称:postgres,代码行数:67,代码来源:fe-print.c
示例15: main
int main(int argc, char **argv)
{
pthread_t timer_thread;
pthread_t comms_thread;
pthread_attr_t pthread_custom_attr;
char buf[1024];
FILE *f;
int c;
extern byte action;
extern byte action_value;
extern int act_after;
if (argc == 1) {
action = ACT_NONE;
exitAfter = 10;
} else if (argc == 5) {
act_after = atoi(argv[1]);
action = atoi(argv[2]);
action_value = atoi(argv[3]);
exitAfter = atoi(argv[4]);
} else {
fprintf(stderr, "Usage: ./master action_after action action_val exit\n");
exit(1);
}
switch(fork()) {
case -1:
perror("Fork failed");
exit(1);
case 0:
f = popen("./slave", "r");
while(fgets(buf, 1024, f)) {
printf(buf);
fflush(stdout);
}
pclose(f);
exit(1);
}
printf("Starting master\n");
fflush(stdout);
alarm(10);
address = 0;
rfd = open("0", O_RDONLY);
wfd = open("1", O_WRONLY | O_NONBLOCK);
pthread_attr_init(&pthread_custom_attr);
pthread_create(&timer_thread, &pthread_custom_attr, timer, NULL);
pthread_create(&comms_thread, &pthread_custom_attr, comms, NULL);
comms_main();
pthread_join(timer_thread, NULL);
pthread_join(comms_thread, NULL);
return 0;
}
开发者ID:indazoo,项目名称:OldReprapMendel,代码行数:62,代码来源:master.c
示例16: dbf_show_records
int dbf_show_records (DBF *dbf)
{
int i,err=0;
double cmp;
int len;
ui32 position;
CONDITION *p;
char cmd[256];
char tmpname [L_tmpnam]="/tmp/dbf2txt-XXXXXX";
FILE *fp;
/* Set var_id */
for (p=dbf->condition;p;p=p->next)
{
for (i=0;i<dbf->NumberOfFields;i++)
{
if ((xstrcmpi (dbf->sub_header[i]->FieldName,p->var))==0)
{
p->var_id=i;
break;
}
}
if (i==dbf->NumberOfFields)
{
printf ("field \'%s\' not found in archive dbf\n",p->var);
err=-1;
}
}
if (err)
return err;
if ((mkstemp(tmpname))<0)
{
perror ("mkstemp");
return -1;
}
if ((fp=fopen (tmpname,"w"))==NULL)
{
printf ("Cannot open `%s`\n",tmpname);
perror ("");
return -1;
}
/* Applying conditions */
dbf->NumberOfRecords=0;
for (i=1;i<=dbf->header->NumberOfRecords;i++)
{
_dbf_load_record (dbf->fp_in, dbf->header, dbf->record, i, dbf->header->LengthOfOneDataRecord);
if (_dbf_isdelete(dbf->record)>0)
continue;
p=dbf->condition;
while (p)
{
position=char2ui32(dbf->sub_header[p->var_id]->DisplacementOfFieldInRecord);
len=LengthOfField(dbf->sub_header[p->var_id]);
if (_dbf_isnumeric(dbf->sub_header[p->var_id]))
cmp=(strtod(dbf->record+position,NULL) - strtod(p->val,NULL));
else
cmp=(double)strncmp (dbf->record+position,p->val,strlen(p->val));
if ( (p->op_id==EQ && cmp==0) || (p->op_id==LT && cmp<0) ||
(p->op_id==LE && cmp<=0) || (p->op_id==GT && cmp>0) ||
(p->op_id==GE && cmp>=0) || (p->op_id==NE && cmp!=0) )
p=p->next;
else
break;
}
if (p==NULL)
{
dbf->NumberOfRecords++;
dbf_push_record (dbf, i, fp);
}
}
fclose (fp);
if (dbf->NumberOfRecords==0)
{
printf ("Record not found!\n");
return 0;
}
sprintf (cmd,"LC_COLLATE=C sort %s -k2",tmpname);
fp=popen (cmd, "r");
err=dbf_dump (dbf,fp,tmpname);
return err;
}
开发者ID:ixamit,项目名称:dbf2txt,代码行数:94,代码来源:dbf2txt.c
示例17: save_environment
/**
* save_environment: save configuration data and arguments.
*/
static void
save_environment(int argc, char *const *argv)
{
char command[MAXFILLEN];
STRBUF *sb = strbuf_open(0);
STRBUF *save_c = strbuf_open(0);
STRBUF *save_a = strbuf_open(0);
int i;
const char *p;
FILE *ip;
/*
* save config values.
*/
snprintf(command, sizeof(command), PQUOTE "%s --config" PQUOTE, quote_shell(gtags_path));
if ((ip = popen(command, "r")) == NULL)
die("cannot execute '%s'.", command);
while (strbuf_fgets(sb, ip, STRBUF_NOCRLF) != NULL) {
for (p = strbuf_value(sb); *p; p++) {
if (*p == '\'') {
strbuf_putc(save_c, '\'');
strbuf_putc(save_c, '"');
strbuf_putc(save_c, '\'');
strbuf_putc(save_c, '"');
strbuf_putc(save_c, '\'');
} else
strbuf_putc(save_c, *p);
}
}
if (pclose(ip) != 0)
die("terminated abnormally '%s' (errno = %d).", command, errno);
strbuf_close(sb);
save_config = strbuf_value(save_c);
/* doesn't close string buffer for save config. */
/* strbuf_close(save_c); */
/*
* save arguments.
*/
{
char *opt_gtagsconf = "--gtagsconf";
for (i = 1; i < argc; i++) {
char *blank;
/*
* skip --gtagsconf because it is already read
* as config value.
*/
if ((p = locatestring(argv[i], opt_gtagsconf, MATCH_AT_FIRST))) {
if (*p == '\0')
i++;
continue;
}
blank = locatestring(argv[i], " ", MATCH_FIRST);
strbuf_putc(save_a, ' ');
if (blank)
strbuf_putc(save_a, '\'');
strbuf_puts(save_a, argv[i]);
if (blank)
strbuf_putc(save_a, '\'');
}
}
save_argv = strbuf_value(save_a);
/* doesn't close string buffer for save arguments. */
/* strbuf_close(save_a); */
}
开发者ID:luchachen,项目名称:global,代码行数:70,代码来源:htags.c
< |
请发表评论