2014年11月12日水曜日

開発環境

Head First C ―頭とからだで覚えるCの基本(David Griffiths (著)、Dawn Griffiths (著) 中田 秀基(監訳)(翻訳)、木下 哲也 (翻訳)、オライリージャパン)の9章(プロセスとシステムサービス: 限界を超える)、コードマグネット(p.422)を解いてみる。

その他参考書籍

コードマグネット(p.422)

コード(BBEdit, Emacs)

newshound.c

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

int main(int argc, char *argv[])
{
  char *feeds[] = {"http://rss.cnn.com/rss/edition.rss",
                   "http://rss.cnn.com/rss/edition_world.rss",
                   "http://rss.cnn.com/rss/edition_africa.rss",
                   "http://rss.cnn.com/rss/edition_americas.rss",
                   "http://rss.cnn.com/rss/edition_asia.rss",
                   "http://rss.cnn.com/rss/edition_europe.rss",
                   "http://rss.cnn.com/rss/edition_meast.rss",
                   "http://rss.cnn.com/rss/edition_us.rss"};
  int times = 3;
  char *phrase = argv[1];
  int i;
  for (i = 0; i < times; i++) {
    char var[255];
    sprintf(var, "RSS_FEED=%s", feeds[i]);
    char *vars[] = {var, NULL};
    pid_t pid = fork();
    if (pid == -1) {
      fprintf(stderr, "プロセスをフォークできません:%s\n", strerror(errno));
      return 1;
    }
    if (pid == 0) {
      if (execle("/usr/bin/python", "/usr/bin/python", "rssgossip.py", phrase,
                 NULL, vars) == -1) {
        fprintf(stderr, "スクリプトを実行できません。: %s\n", strerror(errno));
        return 1;
      }
    }
  }
  return 0;
}

Makefile

P=
CC=cc
CFLAGS=-g -Wall # -O3
SRC=
OBJ=
LDLIBS=

$(P): $(OBJ)
 $(CC) $(CFLAGS) $(LDLIBS) $(OBJ) -o $@


入出力結果(Terminal)

$ make newshound
cc -g -Wall     newshound.c   -o newshound
$ ./newshound_before US
White House, Beijing set historic emissions levels
Official: Russia behind violence
Russia to build Iran nuclear reactors 
Suspicious mail in New Zealand
Gun sales spike in Ferguson
Killed teen's parents: World must know
Rihanna Instagrams the White House
Sex museums: A global guide
11 illustrations that altered history
Pollution causing expats to flee China
5 ways Obama can push back in Asia
Can Google be trusted?
Inside Europe's strangest sausages
$ ./newshound US
Life in Goma just got sweeter
Life in Goma just got sweeter
West Africa's musclemen
Prosecutors appeal Pistorius judgment, sentence
White House, Beijing set historic emissions levels
Official: Russia behind violence
Russia to build Iran nuclear reactors 
Suspicious mail in New Zealand
Gun sales spike in Ferguson
Killed teen's parents: World must know
Rihanna Instagrams the White House
Sex museums: A global guide
11 illustrations that altered history
Pollution causing expats to flee China
5 ways Obama can push back in Asia
Can Google be trusted?
Inside Europe's strangest sausages
57 killed in Pakistan bus wreck
Sex museums: A global guide
Is ISIS inspiring Australia attacks?
Mysterious space mission ends
Russia to build nuclear reactors in Iran
Israeli soldier stabbed at bus stop
Poppy hijab honors Muslims
$

0 コメント:

コメントを投稿