2014年9月24日水曜日

開発環境

Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の10章(プロセス間通信: お話は楽しい)、エクササイズ(p.447)を解いてみる。

その他参考書籍

エクササイズ(p.447)

コード(BBEdit, Emacs)

news_opener.c

#include <stdio.h>
#include <unistd.h>

#include "error.h"
#include "sample447.h"

int main(int argc, char *argv[])
{
  char *phrase = argv[1];
  char *vars[] = {"RSS_FEED=http://rss.cnn.com/rss/edition.rss", NULL};
  int fd[2];

  if (pipe(fd) == -1)
    error("パイプを作成できません");

  pid_t pid = fork();
  if (pid == -1)
    error("プロセスをフォークできません");

  if (!pid) {
    close(fd[0]);
    dup2(fd[1], 1);
    if (execle("/usr/bin/python", "/usr/bin/python", "rssgossip.py", "-u",
               phrase, NULL, vars) == -1)
      error("スクリプトを実行できません");
  }
  dup2(fd[0], 0);
  close(fd[1]);
  char line[255];
  while (fgets(line, 255, stdin))
    if (line[0] == '\t')
      open_url(line + 1);

  return (0);
}

Makefile

CC=cc
CFLAGS=-g -Wall
SRC=news_opener.c error.c sample447.c
OBJ=news_opener.o error.o sample447.o

all: news_opener

news_opener: $(OBJ)
 $(CC) $(CFLAGS) $(OBJ) -o news_opener

news_opener.o: news_opener.c
 $(CC) $(CFLAGS) -c news_opener.c -o news_opener.o

error.o: error.c
 $(CC) $(CFLAGS) -c error.c -o error.o

sample447.o: sample447.c
 $(CC) $(CFLAGS) -c sample447.c -o sample447.o

clear:
 rm -rf news_opener $(OBJ)

入出力結果(Terminal)

$ make
cc -g -Wall -c news_opener.c -o news_opener.o
cc -g -Wall news_opener.o error.o sample447.o -o news_opener
$ ./news_opener 'world'
cmd /c start http://edition.cnn.com/2014/09/05/world/gallery/this-artist-has-created-the-worlds-most-frustrating-objects/index.html?eref=edition

sh: cmd: command not found
x-www-browser 'http://edition.cnn.com/2014/09/05/world/gallery/this-artist-has-created-the-worlds-most-frustrating-objects/index.html?eref=edition
' &
open 'http://edition.cnn.com/2014/09/05/world/gallery/this-artist-has-created-the-worlds-most-frustrating-objects/index.html?eref=edition
'
sh: line 1: x-www-browser: command not found
cmd /c start http://edition.cnn.com/2014/09/22/travel/best-nightlife-cities/index.html?eref=edition

sh: cmd: command not found
x-www-browser 'http://edition.cnn.com/2014/09/22/travel/best-nightlife-cities/index.html?eref=edition
' &
open 'http://edition.cnn.com/2014/09/22/travel/best-nightlife-cities/index.html?eref=edition
'
sh: line 1: x-www-browser: command not found
cmd /c start http://edition.cnn.com/video/data/2.0/video/us/2014/09/23/pkg-man-carries-cross-around-the-world.kait.html?eref=edition

sh: cmd: command not found
x-www-browser 'http://edition.cnn.com/video/data/2.0/video/us/2014/09/23/pkg-man-carries-cross-around-the-world.kait.html?eref=edition
' &
open 'http://edition.cnn.com/video/data/2.0/video/us/2014/09/23/pkg-man-carries-cross-around-the-world.kait.html?eref=edition
'
sh: line 1: x-www-browser: command not found
cmd /c start http://edition.cnn.com/2014/09/22/business/coolest-brands-list/index.html?eref=edition

sh: cmd: command not found
x-www-browser 'http://edition.cnn.com/2014/09/22/business/coolest-brands-list/index.html?eref=edition
' &
open 'http://edition.cnn.com/2014/09/22/business/coolest-brands-list/index.html?eref=edition
'
sh: line 1: x-www-browser: command not found
$

0 コメント:

コメントを投稿