C¿Í python¿¡ °üÇÑ Â©¸·ÇÑ ¿¹Á¦$Date: 2010/02/03 06:51:14 $
  Copyright © 2002 by GNU GPL ÇÁ·Î±×·¥À» ÇÏ¸é¼ Æ´Æ´ÀÌ ¿¹Á¦ ÇÁ·Î±×·¥À» ÀÛ¼ºÇϰí, ´Ù¸¥ °÷¿¡ ÀÖ´Â ¿¹Á¦¸¦ ¸ð¾Æ ³õÀº °ÍÀÔ´Ï´Ù.. | 고친 과정 | 
|---|
 | 고침 0.1 | 2002-11-16 | 고친이 ±è ¿ëÀÏ |  | ÃÖÃÊ ÀÛ¼º |  
 
 ÇÁ·Î±×·¥À» ÇÏ¸é¼ Æ´Æ´ÀÌ ¿¹Á¦ ÇÁ·Î±×·¥À» ÀÛ¼ºÇϰí, ´Ù¸¥ °÷¿¡ ÀÖ´Â ¿¹Á¦¸¦ ¸ð¾Æ ³õÀº °ÍÀÔ´Ï´Ù.. ÁÖ·Î C¿Í python¿¡ °ü·ÃµÈ ¹®¼ ÀÔ´Ï´Ù. 
 ÇѱÛÀ» »ì¸®°í ³ª¶ó¸¦ »ì¸®´Â ±æÀº, °úÇÐÀûÀ¸·Î À¸¶ä°¡´Â ¼¼¹ú½ÄÀ» »ç¿ëÇÏ´Â °Í»ÓÀÔ´Ï´Ù. ´ëÇѹα¹ °úÇбâ¼úÀ» »ì¸®´Â±æÀº ½¬¿î Çѱ۷ΠµÈ ¹®¼¸¦ ¸¸µå°ÍÀÔ´Ï´Ù. ¿Ü±¹¹®¼¸¦ ÀÚ±â È¥ÀÚ¸¸ º¸°í ¸»°ÍÀÌ ¾Æ´Ï¶ó, ½±°Ô ¹ø¿ª, º¸ÃæÇؼ ÃÊÁß°í»ýµé·Î º¼¼ö ÀÖ°Ô ÇØ¾ß ÇÕ´Ï´Ù. ³ª¶ó¸¦ Àß »ì°í, ºÎ°ÇÏ°Ô ÇØ¾ß ÇÏ´Â ÀÌÀ¯´Â ´Ù¸¥³ª¶ó³ª, ÀÎÁ¾¿¡°Ô ¼·¯¿òÀ» ¹ÞÁö ¾Ê±â Çϱâ À§ÇÔÀÔ´Ï´Ù. 
 °ü·Ã¼Àû°ú ¿©·¯ ÀÎÅÍ³Ý »çÀÌÆ®¸¦ ¿î¿µÇÏ°í °è½Å ºÐµé²² °¨»çÇÕ´Ï´Ù. 
 ÀÌ ¹®¼´Â GNU Free Documentation License ¹öÀü 1.1 ȤÀº ÀÚÀ¯ ¼ÒÇÁÆ®¿þ¾î Àç´Ü¿¡¼ ¹ßÇàÇÑ ÀÌÈÄ ÆÇÀÇ ±ÔÁ¤¿¡ µû¸£¸ç
 ÀúÀ۱ǿ¡ ´ëÇÑ º» »çÇ×ÀÌ ¸í½ÃµÇ´Â ÇÑ ¾î¶°ÇÑ Á¤º¸ ¸Åü¿¡ ÀÇÇÑ º»¹®ÀÇ ÀüÀ糪 ¹ßÃéµµ ¹«»óÀ¸·Î Çã¿ëµË´Ï´Ù. º» ÀúÀÚ´Â ¹®¼ÀÇ ³»¿ëÀÌ ¾ß±âÇÒ ¼ö ÀÖ´Â ¾î¶°ÇÑ °á°ú¿¡ ´ëÇØ¼µµ Ã¥ÀÓÀ» ÁöÁö ¾Ê½À´Ï´Ù. 
 hello.c ¼Ò½º #include <stdio.h>
int main()
{
  printf ("This is test program");
  return 0;
}
     |  
 hello.c ¼Ò½º hello.c ÄÄÆÄÀÏÇϱâ gcc -o hello hello.c ./hello ¡Ø gcc ¿É¼Ç c ¾ð¾î´Â ±âº»ÀûÀ¸·Î ÄÄÆÄÀÏÀ» ¸ÕÀú ÇØ¼ object ÈÀÏÀ» ¸¸µé¾î ÁÝ´Ï´Ù. ±×¸®°í ³ª¼ link¸¦ ÇØÁÖ¾î¼ ½ÇÇà ÈÀÏÀ» ¸¸µé¾î ÁÝ´Ï´Ù. -o name : ½ÇÇà ÈÀÏ À̸§À» Á¤Çؼ ¸¸µé¾î ÁØ´Ù. -c : ÄÄÆÄÀϸ¸ ÇÑ´Ù. make »ç¿ëÇϱâ # all ¸í·ÉÀ» ½ÇÇàÇÑ´Ù.
all:   excute 
# ¿ÀÇÁÁ§Æ® ÈÀÏÀ» ¸¸µç´Ù.
object:     hello.o
# ½ÇÇà ÈÀÏ ¸¸µç´Ù.
excute :        hello
# ¿ÀÇÁÁ§Æ® ÈÀÏÀ» Áö¿î´Ù.
clean:
            rm -f collage *.o
     |  
 make ½ÇÇà cc    -c hello.c -o hello.o
cc   hello.o   -o hello
     |  
 À̶§ ¿ÀÇÁ Á§Æ® ÈÀÏÀÌ ¾ø¾î¾ß ÇÑ´Ù.(*.o) hello ½ÇÇà 
 autoscan mv configure.scan configure.in configure.in ¼öÁ¤ dnl Process this file with autoconf to produce a configure script.
AC_INIT()
AC_CONFIG_HEADER(config.h)
dnl Checks for programs.
.....
.....
.....
AC_OUTPUT( Makefile )
     |  
 aclocal autoheader autoconf automake (--add-missing) ./configure 
 Á¤Àû ¶óÀ̺귯¸® .a °øÀ¯ ¶óÀ̺귯¸® .so, .sa Á¤Àû ¶óÀ̺귯ÀÇ ´ÜÁ¡Àº µ¿½Ã¿¡ ¿©·¯ ÇÁ·Î±×·¥À» ¶ç¿üÀ» °æ¿ì À̵éÀÌ ¸ðµÎ °°Àº ¶óÀ̺귯¸®ÀÇ ÇÔ¼öµéÀ» »ç¿ëÇÔÀ¸·Î½á ¸Þ¸ð¸®¿¡ °°Àº ÇÔ¼öµéÀ» ¿©·¯ ¹ø º¹»çÇϰí, ÇÁ·Î±×·¥ ÆÄÀÏ¿¡µµ °°Àº ¶óÀ̺귯¸®¸¦ ¿©·¯ ¹ø º¹»ç¸¦ ÇÑ´Ù´Â °ÍÀÌ´Ù. ÀÌ´Â ¸Þ¸ð¸® ¿ë·®°ú µð½ºÅ© ¿ë·®À» ¸¹ÀÌ ¼Ò¸ðÇÑ´Ù. ¸¹Àº À¯´Ð½º ½Ã½ºÅÛ¿¡¼´Â ÀÌ·¯ÇÑ ºÒÆíÇÔÀ» ±Øº¹ÇÒ ¼ö ÀÖµµ·Ï °øÀ¯ ¶óÀ̺귯¸®¸¦ Á¦°øÇÑ´Ù. python °øÀ¯ ¸ðµâ ¸¸µé±â #!/bin/bash
echo $1
if [ $# = 0 ] ;then
    echo "»ç¿ë¹ý : È®ÀåÀÚ(.c)¸¦ »« ¼Ò½º À̸§À» ÀÔ·ÂÇϼ¼¿ä."
    exit 0
fi
swig -python -module $1 $1.c
gcc -c $1.c $1_wrap.c -I/usr/include/python1.5 -I/usr/lib/python1.5/config
ld -shared $1.o $1_wrap.o -o $1module.so
         |  
 
 
 ´ëÈ¹æ ¼¹ö ÀÔ´Ï´Ù. ÄÄÆÄÀÏ : gcc -o talker_server talk_server.c ½ÇÇà : talk_server 3000 ¼Ò½º #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define MAXLINE 512
char * escapechar = "exit";
int main(int argc, char * argv[]) 
{
int server_fd, client_fd;
int clilen, num;
char sendline[MAXLINE], recvline[MAXLINE];
int size;
pid_t pid;
struct sockaddr_in client_addr, server_addr;
  if(argc != 2) 
  {
    printf("»ç¿ë¹ý : %s port  ", argv[0]);
    exit(0);
  }
  if((server_fd = socket(PF_INET, SOCK_STREAM, 0)) < 0) 
  {
    printf("Server : Can't open stream socket ");
    exit(0);
  }
  bzero((char *) & server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = htonl(INADDR_ANY);
  server_addr.sin_port = htons(atoi(argv[1]));
  if(bind(server_fd, (struct sockaddr *) & server_addr, sizeof(server_addr)) < 0) 
  {
    printf("Server : Can't bind local address");
    exit(0);
  }
  printf("Server started. Waiting for client.. ");
  listen(server_fd, 1);
  clilen = sizeof(client_addr);
  if((client_fd = accept(server_fd, (struct sockaddr *) & client_addr, &clilen)) < 0) 
  {
    printf("Server : failed in accepting.");
    exit(0);
  }
  if(( pid = fork()) > 0) 
  {
    while(fgets(sendline, MAXLINE, stdin ) != NULL) 
    {
      size = strlen(sendline);
      if(write(client_fd, sendline, strlen(sendline)) != size) printf("Error in write ");
      if(strstr(sendline, escapechar) != NULL) 
      {
        printf("Good bye.");
        close(client_fd);
        exit(0);
      }
    }
  } else if (pid == 0) 
  {
  while(1) 
  {
    if((size = read(client_fd, recvline, MAXLINE)) < 0) 
    {
      printf("Error if read ");
      close(client_fd);
      exit(0);
    }
    recvline[size] = '';
    if(strstr(recvline, escapechar) != NULL) break;
    printf("%s", recvline);
    }
  }
  close(server_fd);
  close(client_fd);
  return 0;
}
     |  
 
 ´ëȹæ Ŭ¶óÀÌ¾ðÆ® ÀÔ´Ï´Ù. ÄÄÆÄÀÏ : gcc -o talk_client talk_client.c ½ÇÇà : talk_client SERVERIP 3000 ¼Ò½º #include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#define MAXLINE 1024
char *escapechar = "exit";
int main(int argc, char *argv[]) 
{
  char line[MAXLINE], sendline[MAXLINE], recvline[MAXLINE+1];
  int n, size, comp;
  pid_t pid;
  static int s;
  static struct sockaddr_in server_addr;
  if(argc != 3) 
  {
    printf("»ç¿ë¹ý : %s server_IP port ", argv[0]);
    exit(0);
  }
  if((s = socket(PF_INET, SOCK_STREAM, 0)) < 0) 
  {
    printf("Client: Can't open stream socket. ");
    exit(0);
  }
  bzero((char *) & server_addr, sizeof(server_addr));
  server_addr.sin_family = AF_INET;
  server_addr.sin_addr.s_addr = inet_addr(argv[1]);
  server_addr.sin_port = htons(atoi(argv[2]));
  if(connect(s, (struct sockaddr *) & server_addr, sizeof(server_addr)) < 0) 
  {
    printf("Client: can't connect to server. ");
    exit(0);
  }
  if(( pid = fork()) > 0) 
  {
    while(fgets(sendline, MAXLINE, stdin) != NULL) 
    {
      size = strlen(sendline);
      if(write(s, sendline, strlen(sendline)) != size) printf("Error in write ");
      if(strstr(sendline, escapechar) != NULL) 
      {
        printf("Good bye. ");
        close(s);
        exit(0);
      }
    }
  } else if(pid == 0) 
  {
    while(1) 
    {
      if((size = read(s, recvline, MAXLINE)) < 0) 
      {
        printf("Error if read ");
        close(s);
      }
      recvline[size] = '';
      if(strstr(recvline, escapechar) != NULL) break;
      printf("%s", recvline);
    }
  }
  close(s);
  return 0;
}
     |  
 
 ÇÁ·Î±×·¥ ½ÇÇÛÇÒ¶§ÀÇ  ÀÎÀÚ Ã³¸® ¹æ¹ýÀÔ´Ï´Ù. #include <stdio.h>
char *programname; // usage()
char a;
char *b = "";
unsigned int d = 1;
void usage ();
int main(int argc, char **argv)
{
char option;
extern char *optarg;
programname = argv[0]; // ÇÁ·Î±×·¥ À̸§À» º¯¼ö¿¡ ³Ö´Â´Ù.
  if (argc < 2) usage (); // ÀÎÀÚ°¡ ¾øÀ¸¸é usage() ÇÔ¼ö È£Ãâ
  while ((option = getopt (argc, argv, "a:b")) != -1) 
  { // ÀÎÀÚ Ã³¸® ÇÔ¼ö 
    switch (option) 
    {
      case 'a':
        a = 1;
        break;
      case 'b':
        b = optarg;
        break;
      default:
        usage ();
    }
  }
  printf("a : %d , b : %s", a, b);
  return 0;
}
void usage ()
{
    printf ("»ç¿ë¹ý : %s [-a ÀÎÀÚ] [-b ÀÎÀÚ] [-c ÀÎÀÚ] [-d ÀÎÀÚ]", programname);
    exit (1);
}
     |  
 
 daytime.c  ¼Ò½ºÀÔ´Ï´Ù. #include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#define BUF_LEN 128
int main(int argc, char *argv[]) 
{
int sockfd, n;
char *haddr;
struct sockaddr_in server_addr; /* ¼¹ö ÁÖ¼Ò¸¦ ³ÖÀ» ±¸Á¶Ã¼ */
char buf[BUF_LEN + 1];
  if(argc != 2) 
  {
    printf("»ç¿ë¹ý : %s ip_address", argv[0]);
    exit(0);
  }
  haddr = argv[1];
  if((sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) 
  {
    printf("¼ÒÄÏÀ» ¸¸µé¼ö ¾ø½À´Ï´Ù.");
    exit(0);
  }
  bzero((char *) &server_addr, sizeof(server_addr)); /* Ãʱâȸ¦ ÇØÁØ´Ù. */
  server_addr.sin_family = AF_INET;
  server_addr.sin_port = htons(13); /* daytime ¼¹ö Æ÷Æ®¸¦ ¼³Á¤ÇÑ´Ù. */
  server_addr.sin_addr.s_addr = inet_addr(argv[1]);
  if(connect(sockfd, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) 
  {
    printf("¼¹ö Æ÷Æ®¿¡ Á¢¼ÓÀ» ÇÒ¼ö ¾ø½À´Ï´Ù.");
    exit(0);
  }
  while((n = read(sockfd, buf, BUF_LEN)) > 0) 
  {
    buf[n] = '';
    if(fputs(buf, stdout ) == EOF) printf("aaaa");
  }
  close(sockfd);
  return 0;
}
     |  
 
 ÄÜÆ®·Ñ ŰÀÇ Á¶ÇÕ ÇÒ¶§ »ç¿ëÇÏ´Â ÇÔ¼ö ÀÔ´Ï´Ù. ½Ã±×³Î ÇÔ¼ö : /usr/include/bits/signum.h ÄÄÆÄÀÏ : gcc -o signal_test signal_test.c ½ÇÇà : ./signal_test ¼Ò½º #include <sys/types.h>
#include <signal.h>
#include <stdio.h>
#include <unistd.h>
int my_signal(void); // »õ·Î¿î ½Ã±×³Î ÇÔ¼ö¸¦ ¼±¾ðÇÑ´Ù.
int count = 0;  // ctrl-c ÀԷ Ƚ¼ö Ä«¿îÅÍ
int main()
{
  int i = 0;
  if(signal(SIGINT, my_signal) == SIG_ERR) 
  { // ½Ã±×³Î ÇÔ¼ö¸¦ ÀÛµ¿ ½ÃŲ´Ù.
    printf("singal() error");
    exit(0);
  }
  while(count < 3) 
  { // contrl-c ÀÔ·ÂÀÌ 3¹ø±îÁö 
    sleep(1); // 1Ãʰ¡ Á¤Áö
    printf("%d", i++); //  ctrl-c Ä«¿îÅÍ
  }
  return 0;
}
int my_signal(void)
{
  printf("Ctrl-C pressed. ");
  count++;
  return 0;
}
     |  
 
 ÄÄÆÄÀÏ : gcc -o test test.c ¼Ò½º1 #include <stdio.h>
#include <fcntl.h>
int main()
{
    char hostname[124];
    FILE *fd;
    fd = fopen("/proc/sys/kernel/hostname", "r");
    fread(hostname, sizeof(hostname), 1, fd);
    printf("%s", hostname);
    return 0;
}
     |  
 ¼Ò½º2 #include <unistd.h>
#include <netdb.h>
int main ()
{
  struct hostent* hoststruct;
  char hostname[255];
  gethostname(hostname, 100);
  hoststruct = gethostbyname(hostname);
  printf("È£½ºÆ® À̸§Àº %s ÀÔ´Ï´Ù.\n", hoststruct->h_name);
  return 0;
}
     |  
 
 hello.po¸¦ ¸¸µé¾î ÁØ´Ù. xgettext -a -d hello -k_ -s hello.c mo ÈÀÏÀ» ¸¸µé¾î ÁÖ´Â »ç¿ë¹ýÀÔ´Ï´Ù. msgfmt hello.po messages ¶ó´Â ÈÀÏÀÌ »ý±â´Âµ¥ À̰ÍÀ» À̸§À» ¹Ù²Ù¾î ÁÖ¸é µË´Ï´Ù. mv hello.po hello.mo ·ÎÄÉÀÏ µð·ºÅ丮¿¡ Ä«ÇǸ¦ ÇÕ´Ï´Ù. cp hello.mo /usr/share/locale/ko/LC_MESSAGES/hello.mo ¼Ò½º¸¦ ÄÄÆÄÀÏ ÇÕ´Ï´Ù.  
         gcc -o hello hello.c 
      ¼Ò½º #include <locale.h>
#include <stdio.h>
#include <libintl.h>
#define _(String) gettext (String)
int main(void)
{
    setlocale (LC_ALL, "");
    bindtextdomain ("hello", "/usr/share/locale/");
    textdomain ("hello");
    puts (_("hello"));
    return 0;
}
        |  
 hello.po #: hello.c:24
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: 1.0\n"
"POT-Creation-Date: 2001-03-08 17:06+0900\n"
"PO-Revision-Date: 2001-03-08 17:06+0900\n"
"Last-Translator: Kim Yong Il <nalabi@formail.org>\n"
"Language-Team: Uniwork Project Team <nalabi@formail.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=ecu-kr\n"
"Content-Transfer-Encoding: 8-bit\n"
#: hello.c:25 hello.c:26 hello.c:28
msgid "hello"
msgstr "¾È³çÇϼ¼¿ä
         |  
 Makefile # Makefile for locale directory
CWD = locale
MSGFMT = msgfmt
SUB_DIRS =
FILES_PO:=$(wildcard *.po)
FILES_MO:=$(FILES_PO:.po=.mo)
LOCALEDIR ?= /usr/share/locale
ifeq ($(enable_nls),1)
all: mo-files
mo-files: $(FILES_MO)
install:
    $(MAKE) all
    for f in *.mo ; do mkdir -p \
        $(INSTALL_PREFIX)$(LOCALEDIR)/`basename $$f .mo`/LC_MESSAGES ; \
        cp $$f $(INSTALL_PREFIX)$(LOCALEDIR)/`basename $$f .mo`/LC_MESSAGES/gkrellm.mo ; done
%.mo: %.po
    $(MSGFMT) -f -v -o $@ $<
else
all:
install:
endif
clean:
    $(RM) $(FILES_MO)
         |  
 
 
 ¼Ò½º #include "stdio.h"
#define TEST(test)      my_func_##test()
#define test(num)       __asm__ __volatile__("call test_" #num::);
void my_func_hello(void)
{
  printf("HELLO !!\n");
}
void my_func_goodbye(void)
{
  printf("Good Bye !!\n");
}
void test_1(void)
{
  printf("This is test_1 function\n");
}
void test_2(void)
{
  printf("This is test_2 function\n");
}
int main()
{
  int i;
  TEST(hello);
  TEST(goodbye);
  test(1);
  test(2);
  return 0;
}
         |  
 ÄÄÆÄÀÏ gcc -o t test.c ½ÇÇà HELLO !!
Good Bye !!
This is test_1 function
This is test_2 function
       |  
 
 
 ¼Ò½º #include 
int ftw_find();
int main(int argc, char *argv[])
{
  if (argc > 1)
  {
    ftw(argv[1],ftw_find, 0);
  }
  else
  {
    printf("Usage: %s dir\n", argv[0]);
  }
  return 0;
}
int ftw_find(const char *path, struct stat *sb, int flag)
{
  if(strstr(path,"ã°íÀÚ ÇÏ´Â ÆÄÀÏÀ̳ª µð·ºÅ丮")!=NULL)
  {
    printf("%s:\t%u\t\n", path, sb->st_size);
    exit(0);
  }
  return 0;
}
     |  
 
 unistd.h Çì´õ /usr/src/linux-2.4.18# vi include/asm/unistd.h #define __NR_lremovexattr   236
#define __NR_fremovexattr   237
#define __NR_mycall         238
     |  
 entry.S /usr/src/linux-2.4.18# vi arch/i386/kernel/entry.S     .long SYMBOL_NAME(sys_ni_syscall)   /* reserved for lremovexattr */
    .long SYMBOL_NAME(sys_ni_syscall)   /* reserved for fremovexattr */
    .long SYMBOL_NAME(sys_mycall) 		/* 238 mycall */
     |  
 mycall.c /usr/src/linux-2.4.18# vi kernel/mycall.c #include <linux/kernel.h>
#include <linux/errno.h>
asmlinkage void sys_mycall()
{       
    printk("Corea Manse!!!!\n");
} 
     |  
 krernel/Makefile /usr/src/linux-2.4.18# vi kernel/Makefile obj-y     = sched.o dma.o fork.o exec_domain.o panic.o printk.o \
        module.o exit.o itimer.o info.o time.o softirq.o resource.o \
        sysctl.o acct.o capability.o ptrace.o timer.o user.o \
        signal.o sys.o kmod.o context.o mycall.o
     |  
 user Makefile COMPILE=gcc
INCLUDEDIR = /usr/src/linux-2.4.18/include
MODCFLAGS := -I$(INCLUDEDIR)
mycall_app : mycall_app.c
    $(COMPILE) $(MODCFLAGS) -o $@ $^
     |  
 ¼Ò½º (mycall_app.c) #include <linux/unistd.h>
/* system call stub function */
_syscall0(void, mycall);
main()
{
  mycall();
}
     |  
 
 ¼Ò½º #include <netinet/ether.h>
#include <net/ethernet.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
int main (int argc, char *argv[])
{
  struct ifreq *iflist;
  struct sockaddr *sa;
  int fd;
  char *out;
  if(argc != 2) 
  {
    printf("Usage: progname ifname (ex: progname eth0)\n");
    return -1;
  }
 
  iflist = malloc (sizeof (struct ifreq));
  fd = socket (PF_INET, SOCK_STREAM, 0);
  strncpy (iflist->ifr_name, argv[1], strlen (argv[1]));
  if (ioctl (fd, SIOCGIFHWADDR, iflist) == -1)
  {
    perror ("ioctl failed");
    return -1;
  }
  sa = &(iflist->ifr_hwaddr);
  out = ether_ntoa ((struct ether_addr *) sa->sa_data);
  printf ("%s\n", out);
  return 0;
}
     |  
 
 g++ À» ÀÌ¿ëÇØ¼ È£½ºÆ® À̸§À» Ãâ·ÂÇÏ´Â Å×½ºÆ® ÇÁ·Î±×·¥ÀÔ´Ï´Ù. ÄÄÆÄÀÏ : g++ -o test test.cpp ¼Ò½º #include <unistd.h>
#include <string>
// Ŭ·¡½º¸¦ ¼±¾ðÇϳª.
class Init
{
private:
public:
  static string get_hostname();
};
// get_hostname À̶ó´Â ÇÔ¼ö¸¦ ¸¸µé¾î ÁØ´Ù.
string Init::get_hostname()
{
  char buf[128]; // È£½ºÆ® À̸§ÀÌ µé¾î°¥ º¯¼ö¸¦ ¼±¾ð
  string ret; 
  // È£½ºÆ® À̸§À» ¾ò´Â ÇÔ¼ö¸¦ È£ÃâÇÑ´Ù.
  if((gethostname ( buf, sizeof(buf) )) < 0) 
  {
    ret.assign("Unkown Hostname"); // È£½ºÆ® À̸§ÀÌ ¾øÀ» °æ¿ì
  } else 
  {
    ret.assign(buf); // È£½ºÆ® À̸§À» ¾ò¾úÀ» °æ¿ì
  }
  return ret;  // °á°ú °ªÀ» ¸®ÅÏÇÑ´Ù.
}
int main(void) 
{
  cout << Init::get_hostname() << endl; // ȸ鿡 Ãâ·ÂÇÑ´Ù.
  return 0;
}
     |  
 
 ¼Ò½º #include <string>
// Hello °´Ã¼¸¦ ¸¸µç´Ù.
class Hello 
{
  private:
  public:
    // ÇÔ¼ö¸¦ Çϳª ¸¸µç´Ù.
    void displayData() 
    {
      cout << "I am class" << endl; // Ãâ·ÂÀ» ÇÑ´Ù.
    }
};
int main(void)
{
  Hello hello; //hello °´Ã¼¸¦ ¼±¾ðÇÑ´Ù.
  hello.displayData(); //Ãâ·ÂÇÑ´Ù.
  return 0;
}
     |  
 °á°ú 
 ¼Ò½º #include <gtk/gtk.h>
int main( int   argc, char *argv[] )
{
    GtkWidget *window;
    gtk_init (&argc, &argv);
    window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_usize(window, gdk_screen_width(), gdk_screen_height());
    gtk_widget_set_uposition(window, 0, 0);
    gtk_widget_realize(window);
    gdk_window_set_decorations(window->window, 0);
    gtk_widget_show  (window);
    gtk_main ();
    return 0;
}
     |  
 ÄÄÆÄÀÏ : gcc test.c -o test `gtk-config --cflags --libs` 
 ¸®¼Ò½º ÈÀÏ ÀÛ¼ºÇÑ´Ù. (testrc) style "button"
{
    fg[PRELIGHT] = { 1.0, 1.0, 1.0 }  # ±ÛÀÚ»ö ¸¶¿ì½º¸¦ ¿Ã·Á ³õ¾ÒÀ»¶§
    bg[PRELIGHT] = { 0, 0.5, 0.5 }    # ¹è°æ»ö ¸¶¿ì½º¸¦ ¿Ã·Á ³õ¾ÒÀ»¶§
    fg[ACTIVE] = { 0, 0.0, 0.0 }          # ±ÛÀÚ»ö Ŭ¸¯ÇßÀ» °æ¿ì
    bg[ACTIVE] = { 0, 0.6, 0.6 }          # ¹è°æ»ö Ŭ¸¯ÇßÀ» °æ¿ì
    fg[NORMAL] = { 0.0, 0.0, 0.0 }    # ±ÛÀÚ»ö Æò»ó½Ã »ö»ó
    bg[NORMAL] = { 0.0, 0.5, 0.5 }    # ¹è°æ»ö Æò»ó½Ã »ö»ó
    fg[INSENSITIVE] = { 1.0, 0, 1.0 }
    bg[INSENSITIVE] = { 1.0, 1.0, 1.0 }
}
widget "*Button*" style "button"
     |  
 ¼Ò½º #include <gtk/gtk.h>
int main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *button;
  gtk_rc_parse( "testrc" );
  gtk_set_locale();
  gtk_init (&argc, &argv);
  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  button = gtk_button_new_with_label ("¹öư");
  gtk_widget_show (button);
  gtk_container_add (GTK_CONTAINER (window), button);
  gtk_widget_show (window);
  gtk_main ();
  return 0;
}
     |  
 ÄÄÆÄÀÏ : gcc main.c -o main `gtk-config --cflags --libs` 
 ¼Ò½º def mesg(): 
        a = 1
        return a
print mesg()
         |  
 °á°ú ¼Ò½º a = 10
b = 10
def mesg(a, b):
        c = a + b
        return c
print mesg(a, b)
        |  
 °á°ú ¼Ò½º a = 10
b = 10
def mesg(a, b):
        c = a + b
        return c
if __name__ == '__main__':
        print mesg(a, b)
        |  
 °á°ú 
 
 ¼Ò½º #!/usr/bin/env python
from gtk import *
# FirstClass ¶ó´Â °´Ã¼¸¦ ¸¸µì´Ï´Ù.
class FirstClass:
    def setdata(self, value):  # ¾î¶² °ªÀ» ¹Þ´Â setdata ÇÔ¼ö¸¦ ¸¸µì´Ï´Ù.
        self.data = value
    def display(self):         # setdata ¿¡¼ ¹ÞÀº °ªÀ» Ãâ·ÂÇÕ´Ï´Ù.
        print self.data
x = FirstClass()
y = FirstClass()
x.setdata("Kim Yong-Il")
x.display()
y.setdata("3.14159")
y.display()
print "¿À°Ô ¹Ù¸®"
         |  
 °á°ú          python hello1.py Kim Yong-Il
3.14159
¿À°Ô ¹Ù¸®
         |   
      
 
 ¼Ò½º #!/usr/bin/env python
from gtk import *
# FirstClass ¶ó´Â °´Ã¼¸¦ ¸¸µì´Ï´Ù.
class FirstClass:
    def setdata(self, value):  # ¾î¶² °ªÀ» ¹Þ´Â setdata ÇÔ¼ö¸¦ ¸¸µì´Ï´Ù.
        self.data = value
    def display(self):         # setdata ¿¡¼ ¹ÞÀº °ªÀ» Ãâ·ÂÇÕ´Ï´Ù.
        print self.data
# SecondClass ¶ó´Â °´Ã¼¸¦ ¸¸µì´Ï´Ù.
# SecondClass ¶ó´Â °´Ã¼´Â FirstClass °´Ã¼¸¦ Æ÷ÇÔÇÕ´Ï´Ù.
class SecondClass(FirstClass):
    def display(self):         # ȸé Ãâ·Â ÇÔ¼ö¸¦ ¸¸µì´Ï´Ù.
        print 'Current value = "%s"' % self.data
z = SecondClass()
z.setdata(42)
z.display()
print "¿À°Ô ¹Ù¸®"
         |  
 °á°ú python hello2.py Current value = "42"
¿À°Ô ¹Ù¸®
         |  
 
 
 ¼Ò½º #!/usr/bin/env python
from gtk import *
# FirstClass ¶ó´Â °´Ã¼¸¦ ¸¸µì´Ï´Ù.
class FirstClass:
    def setdata(self, value):  # ¾î¶² °ªÀ» ¹Þ´Â setdata ÇÔ¼ö¸¦ ¸¸µì´Ï´Ù.
        self.data = value
    def display(self):         # setdata ¿¡¼ ¹ÞÀº °ªÀ» Ãâ·ÂÇÕ´Ï´Ù.
        print self.data
# SecondClass ¶ó´Â °´Ã¼¸¦ ¸¸µì´Ï´Ù.
# SecondClass ¶ó´Â °´Ã¼´Â FirstClass °´Ã¼¸¦ Æ÷ÇÔÇÕ´Ï´Ù.
class SecondClass(FirstClass):
    def display(self):         # ȸé Ãâ·Â ÇÔ¼ö¸¦ ¸¸µì´Ï´Ù.
        print 'Current value = "%s"' % self.data
# ThirdClass(SecondClass):
# Third ¶ó´Â °´Ã¼´Â Second °´Ã¼¸¦ Æ÷ÇÔÇÕ´Ï´Ù.
class ThirdClass(SecondClass):
    def __init__(self, value):
        self.data = value
    def __add__(self, other):
        return ThirdClass(self.data + other)
a = ThirdClass("abc")
a.display()
b = a + 'xyz'
b.display()
print "¿À°Ô ¹Ù¸®"
         |  
 °á°ú python hello3.py  
Current value = "abc"
Current value = "abcxyz"
¿À°Ô ¹Ù¸®
         |  
 
 
 ¼Ò½º #!/usr/bin/env python
from gtk import *
class Subclass:
    data = 'spam'
    def __init__(self, value):
        self.data = value
    def display(self):
        print self.data, Subclass.data
x = Subclass(1)
y = Subclass(2)
x.display()
y.display()
print "¿À°Ô ¹Ù¸®"
         |  
 °á°ú python hello4.py 
 
 ¼Ò½º #!/usr/bin/env python
from gtk import *
class Super:
    def method(self):
        print 'in Super.method'
class Sub(Super):
    def method(self):
        print 'starting Sub.method'
        Super.method(self)
        print 'ending Sub.method'
x = Super()
x.method()
print "------------------>"
x = Sub()
x.method()
         |  
 °á°ú python hello5.py in Super.method
------------------>
starting Sub.method
in Super.method
ending Sub.method
         |  
 
 
 ¼Ò½º #!/usr/bin/env python
from gtk import *
class Super:
    def method(self):
        print 'in Super.method'
    def delegate(self):
        self.action()
class Inheritor(Super):
    pass
class Replacer(Super):
    def method(self):
        print 'in Replacer.method'
class Extender(Super):
    def method(self):
        print 'starting Extender.method'
        Super.method(self)
        print 'ending Extender.method'
class Provider(Super):
    def action(self):
        print 'in Provider.action'
if __name__ == '__main__':
    for klass in (Inheritor, Replacer, Extender):
        print '
' + klass.__name__ + '...'
        klass().method()
    print '
Provider...'
    Provider().delegate()
         |  
 °á°ú python hello6.py ending Extender.method
Inheritor...
in Super.method
Replacer...
in Replacer.method
Extender...
starting Extender.method
in Super.method
Provider...
         |  
 
 
 ¼Ò½º #!/usr/bin/env python
from gtk import *
class Number:
    def __init__(self, start):
        self.data = start
    def __sub__(self, other):
        return Number(self.data - other)
x = Number(5)
y = x -2
y.data
print y.data
         |  
 °á°ú python hello7.py 
 
 ¼Ò½º #!/usr/bin/env python
from gtk import *
class indexer:
    def __getitem__(self, index):
        return index ** 2
x = indexer()
for i in range(5):
    print x[i],
         |  
 °á°ú python hello8.py 
 
 ÃÖÈñö ¼Ò½º, ironyjk (at) kldp.org /var/mail ¿¡ ÀÖ´Â ¸ÞÀÏÀ» ¿øÇÏ´Â ¸ÞÀÏ ÁÖ¼Ò·Î º¸³½´Ù. ½ÇÇà : cd /var/mail python stmp.py ID ¸áÁÖ¼Ò smtp.py import smtplib , sys
def sendmail ( ff , to , text ) :
    if "@" not in ff :
        print "%s Break" % ff
        return
#   print " toaddr =  %s" % ff
#   print " text ==  %s" % text
    server = smtplib.SMTP('localhost')
    server.sendmail(ff , to , text)
    server.quit()
fromaddr = "root@localhost"
toaddr = sys.argv[2]
f = open ( sys.argv[1] )
line = f.readline()
text = ""
while line :
    if len ( line.split () ) > 2 and line.split ()[0] == "From" :
        sendmail ( fromaddr , toaddr , text )
        fromaddr = line.split ()[1]
        text = ""
    text += line
    line = f.readline()
if text != "" :
    sendmail ( fromaddr , toaddr , text )
     |  
 
 ÃÖÈñö¾¾ ¼Ò½º , ironyjk (at) kldp.org Á¡½É¶§ ¹«¾ùÀ» ¸ÔÀ»±î °í¹ÎÇÒ¶§ Çѹø ½ÇÇàÇØÁÖ¸é µË´Ï´Ù. bab.py import random,smtplib,sys
list = ['Çѱ¹È¸°ü:ÇØ¹°µÈÀå','Çѱ¹È¸°ü:°¥ºñÅÁ', 'Çѱ¹È¸°ü:°¥ºñÅÁ', 'Çѱ¹È¸°ü:ºñºö¹ä','Çѱ¹È¸°ü:¼³··ÅÁ' ,'Çѱ¹È¸°ü:À°°èÀå' ,'»ïÀͽĴç:>¸¸µÎ±¹','»ïÀͽĴç:¹é¹Ý' ,'»ïÀͽĴç:Á¦À°ººÀ½' , '»ïÀͽĴç:±èÄ¡Âî°Ô' , '»ïÀͽĴç:±èÄ¡Âî°Ô' , 'Áß±¹Áý:º¹À½¹ä' , 'Áß±¹Áý:«»Í', 'Áß±¹Áý:>Â¥Àå¸é' , '»ïÀͽĴç:¾ß人À½¹ä' ,'ºÐ½ÄÁý:±èÄ¡º¹À½¹ä','ºÐ½ÄÁý:ºÎ´ëÂî°³']
menu = random.choice (list)
fromaddr = "ID@address.org"
toaddr = "ID@address.org"
msg = "To: %s  Subject:¿À´ÃÀÇ ¸Þ´º!  ¿À´ÃÀÇ ¸Þ´º´Â %s ÀÔ´Ï´Ù." % ( toaddr ,  menu )
if  len ( sys.argv ) >  1 :
  msg = msg + "Áñ°Å¿î Àú³á½Ä»çÀÔ´Ï´Ù. Àú³á½Ä»ç ¾ÈÇÏ½Ç ºÐÀº °ü¸®ÀÚ¿¡°Ô ½Å°í ¹Ù¶ø´Ï´Ù. "
lastmenu = ""
msg += " -- ÇöÀç ¸Þ´º ÇöȲ --  "
for i in list :
  if lastmenu != i :
    msg += " - %s " % i
  lastmenu = i
msg += " »õ·Î¿î ¸Þ´ºÀÇ Ãß°¡´Â ¾ðÁ¦³ª ȯ¿µÇÕ´Ï´Ù.  »õ·Î¿î ¸Þ´º´Â ID@address.org ¸ÞÀÏ º¸³»Áֽñ⠹ٶø´Ï´Ù."
server = smtplib.SMTP('address.org')
server.sendmail(fromaddr, toaddr, msg)
server.quit()
     |  
 
 mysql µ¥ÀÌŸ¸¦ °¡Á® ¿É´Ï´Ù.     
#!/usr/bin/python
import MySQLdb
db = MySQLdb.connect(host="localhost", db="test", user="root" , passwd="")
hash = db.cursor()
hash.execute("select * from test")
result = hash.fetchall()
for i in result:
    print result[0]
db.close()
     |  
 
 ¼Ò½º #!/usr/bin/python
import curses
import time
stdscr=curses.initscr()
curses.start_color()
curses.init_pair(1,curses.COLOR_CYAN, curses.COLOR_BLACK)
stdscr.addstr(10,10,"test", curses.color_pair(1))
stdscr.addstr(12,10,"aaaaaaaa", curses.A_REVERSE)
stdscr.refresh()
time.sleep(5)
curses.endwin()
     |  
 
 ¼¹ö ½ÇÇàÇϱâ /usr/lib/python1.5$ python CGIHTTPServer.py
Serving HTTP on port 8000 ...
         |  
 ·çÆ®±ÇÇÑ »ç¿ëÇϱâ vi CGIHTTPServer.py nobody = nobody_uid()
# ¿©±â¼ ½Ã½ºÅÛÀÇ nobody °èÁ¤ UID¸¦ °¡Á® ¿É´Ï´Ù.
self.wfile.flush() # Always flush before forking
pid = os.fork()
if pid != 0:
    # Parent
    pid, sts = os.waitpid(pid, 0)
    if sts:
        self.log_error("CGI script exit status %#x", sts)
    return
# Child
try:
    try:
        # À̺κÐÀ» nobody·Î »ç¿ëÇÒ °æ¿ì´Â ´ÙÀ½°ú °°ÀÌ Çϰí, ·çÆ®¸¦ »ç¿ëÇÒ°æ¿ì´Â ÁÖ¼®Ã³¸®ÇÕ´Ï´Ù.
        os.setuid(nobody)
    except os.error:
        pass
    os.dup2(self.rfile.fileno(), 0)
    os.dup2(self.wfile.fileno(), 1)
    os.execve(scriptfile, args, env)
except:
    self.server.handle_error(self.request, self.client_address)
         |  
 CGIHTTPServer ¸ðµâ¿¡¼ CGI ½ÇÇàÇ챉          ¸ðµâÀ» ÀÌ¿ëÇØ¼ ´ÙÀ½°ú °°ÀÌ °£´ÜÇÑ ¼¹ö ÇÁ·Î±×·¥À» ÇÒ¼ö ÀÖ½À´Ï´Ù. #!/usr/bin/env python
import CGIHTTPServer
import BaseHTTPServer
Handler = CGIHTTPServer.CGIHTTPRequestHandler
PORT = 8080
httpd = BaseHTTPServer.HTTPServer(("", PORT), Handler)
print "Serving at port ", PORT
httpd.serve_forever()
         |   
        GIHTTPServer.py ¿¡ ¼Ò½º¿¡ º¸¸é cgi µð·ºÅ丮°¡ ´ÙÀ½°ú °°ÀÌ ¼³Á¤ÀÌ µÇ¾î ÀÖ½À´Ï´Ù. 
        ÇÊ¿ä½Ã º¯°æÀ» ÇÒ¼ö ÀÖ½À´Ï´Ù. 
        cgi_directories = ['/cgi-bin', '/htbin'] 
      cgi ÇÁ·Î±×·¥ (test.py) #!/usr/bin/env python
print """Content-type: text/html
¼º°ø Çß½À´Ï´Ù.
"""
         |  
 À§¿Í °°Àº ¿¹Á¦¸¦ ÀÌ¿ëÇØ¼ cgi-bin ¹Ø¿¡ ³Ö¾î¼ ´ÙÀ½°ú °°ÀÌ ½ÇÇàÀ» ÇÏ¸é µË´Ï´Ù. http://localhost:8080/cgi-bin/test.py 
 
 ¼Ò½º import MySQLdb
connection = MySQLdb.connect(user='root', passwd='', db='nalabi')
cursor = connection.cursor()  # Ä¿¼ °´Ã¼¸¦ ¾ò¾î¿Â´Ù.
cursor.execute('select * from test')
res = cursor.description
for record in res:
        print "%-10s %-10s %-10s %-10s %-10s %-10s %-10s" % record
cursor.close() 
     |  
 °á°ú no         3          2          6          6          0          0         
num        3          2          6          6          0          0         
idx        3          2          6          6          0          0         
date       3          9          11         11         0          0         
host       252        13         255        255        0          1         
name       252        6          255        255        0          1         
passwd     253        13         13         13         0          1         
email      252        18         255        255        0          1         
url        252        19         255        255        0          1         
title      252        20         255        255        0          1         
text       252        3243       16777215   16777215   0          1         
refer      3          1          6          6          0          0         
reyn       3          1          1          1          0          0         
reno       3          1          6          6          0          0         
rede       3          1          6          6          0          0         
reto       3          1          6          6          0          0         
html       3          1          1          1          0          0         
moder      3          1          1          1          0          0         
bofile     253        18         100        100        0          1         
bcfile     253        14         100        100        0          1         
bfsize     3          5          4          4          0          1         
     |  
 
 ¼Ò½º import commands, os
import os
out=commands.getoutput("ls -l")
a = out.split ( '\n' )
for x in a:
    b = x.split ()
    if b[0] != "\307\325\260\350"  :
        print b[8]
        cc = "chown %s:%s %s" % (b[8], b[8], b[8])
        commands.getoutput(cc)
     |  
 
 ÈÀÏ Àаí split Çϱâ #!/usr/bin/perl 
&print_file("/etc/webmin/config");
exit;
sub print_file
{
my ($filename) = @_;
  open(fh,"$filename");
  while(< fh>) 
  {
    ($name,$value) = split(/=/,$_);
    if( $name eq "admin_mail" ) 
    {
      print $value;
    }
  }
  close(fh);
}
     |  
  
 
  | 
 |