2018年2月23日金曜日

開発環境

Head First C ―頭とからだで覚えるCの基本 (David Griffiths (著)、Dawn Griffiths (著)、中田 秀基 (監修)、木下 哲也 (翻訳)、オライリージャパン)の9章(プロセスとシステムサービス)、エクササイズ(p. 417)を取り組んでみる。

エクササイズ(p. 417)

//
//  main.c
//  sample1
//
//  Created by kamimura on 2018/02/21.
//  Copyright © 2018 kamimura. All rights reserved.
//

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

int main(int argc, const char * argv[]) {
    char *feeds[] = {
        "http://sitekamimura.blogspot.com/feeds/posts/default",
        "http://sitekamimura.blogspot.com/feeds/comments/default",
    };
    int times = 3;
    char *phrase = (char*)argv[1];
    for (int i = 0; i < times; i++) {
        char var[255];
        sprintf(var, "RSS_FEED=%s", feeds[i]);
        char *vars[] = {var, NULL};
        if (execle("/usr/bin/python", "/usr/bin/python", "rssgossip.py", phrase, NULL, vars) == -1) {
            fprintf(stderr, "スクリプトを実行できません: %s\n", strerror(errno));
            return 1;
        }
    }
    return 0;
}

入出力結果(Terminal)

$ ./rssgossip
Traceback (most recent call last):
  File "rssgossip.py", line 49, in <module>
    searcher = re.compile(args[0], re.IGNORECASE)
IndexError: list index out of range
$ ./rssgossip Python
 - Python - JavaScript -  - 1  1 - ()
 - Python -  - 1  1 - ()
 - Python - JavaScript -  - 1  1 - ()
 - Python - JavaScript -  -  -  - ()
 - Python - JavaScript -  - 1  1 - ()
 - Python -  -  - (())
 - Python - JavaScript -  -  -  - (())
 - Python -  -  - ((gradient)()())
 - Python - JavaScript -  - 1  1 - 1(())
$ ./rssgossip c
 - Survivors of the Holocaust talk about how they defied the odds to rebuild their lives in Australia - !
 - Python - JavaScript -  - 1  1 - ()
C - (unistd.h execlexeclpstring.h strerror errno.h )
 - Did the market crash today and what does it mean for you? - !
C - (time.hasctime)
 - Economics Professor Justin Woolfers talks about today's share market sell off - !
C - ()
 - Python - JavaScript -  - 1  1 - ()
C -  - (stdarg.hva_listva_startva_argva_end)
C -  - ((enum))
 - There's another humanitarian crisis in Syria that could dwarf Aleppo - !
C -  - ((enum)switch )
 - Barnaby Joyce says end of his marriage 'one of the greatest failures of my life' - !
 - Python - JavaScript -  -  -  - ()
C -  - (sdtlib.h qsort)
 - Python - JavaScript -  - 1  1 - ()
 - Adam Bandt apologises to Jim Molan after accusing him of war crimes - !
 - Python - JavaScript -  -  -  - (())
C -  - ()
 - Python - JavaScript -  - 1  1 - 1(())
$ ./rssgossip perl
$ 

0 コメント:

コメントを投稿