トップ «前の日記(2013-10-14) 最新 次の日記(2013-10-16)» 編集

ヨタの日々

2001|08|09|10|11|12|
2002|01|02|03|04|05|06|07|08|09|10|11|12|
2003|01|02|03|04|05|06|07|08|09|10|11|12|
2004|01|02|03|04|05|06|07|08|09|10|11|12|
2005|01|02|03|04|05|06|07|08|09|10|11|12|
2006|01|02|03|04|05|06|07|08|09|10|11|12|
2007|01|02|03|04|05|06|07|08|09|10|11|12|
2008|01|02|03|04|05|06|07|08|09|10|11|12|
2009|01|02|03|04|05|06|07|08|09|10|11|12|
2010|01|02|03|04|05|06|07|08|09|10|11|12|
2011|01|02|03|04|05|06|07|08|09|10|11|12|
2012|01|02|03|04|05|06|07|08|09|10|11|12|
2013|01|02|03|04|05|06|07|08|09|10|11|12|
2014|01|02|03|04|05|06|07|08|09|10|11|12|
2015|01|02|03|04|05|06|07|08|09|10|11|12|
2016|01|02|03|04|05|06|07|08|09|10|11|12|
2017|01|02|03|04|05|06|07|08|09|10|11|12|
2018|01|02|03|04|05|06|07|08|09|10|11|12|
2019|01|02|03|04|05|06|07|08|09|10|11|12|
2020|01|02|03|04|05|06|07|08|09|10|11|12|
2021|01|02|03|04|05|06|07|08|09|10|11|12|
2022|01|02|03|04|05|06|07|08|09|10|11|12|
2023|01|02|03|04|05|06|07|08|12|
2024|01|02|03|04|

2013-10-15 :-)

_ 午前

0730 起床

0900 健康診断

1100 おひる

_ 午後

1200 午後休み

1300 アニメ消化

1500 Cほげ

_

1800 和訳

2130 飯。豚肉の生姜焼き

_ [連結リスト][デザインパターン][Commandパターン][C]連結リストで Command パターン

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>

typedef void (*command_t)(int argc, ...);

struct node_t
{
  struct node_t* next;
  command_t cmd;
} root;

/* 先頭に追加 */
void put(command_t cmd)
{
  struct node_t* _p;
  struct node_t* _q;

  for(_p = &root; _p->next != NULL; _p = _p->next)
    ;

  _q = (struct node_t*)malloc(sizeof(struct node_t));
  if(_q == NULL)
  {
    perror("put");
    exit(0);
  }
  _q->cmd = cmd;
  _q->next = _p->next;
  _p->next = _q;
}

/* 先頭を削除 */
void get(void)
{
  struct node_t* _p;

  _p = root.next;
  if(_p == NULL)
  {
    printf("root is empty\n");
    return;
  }

  root.next = _p->next;
  free(_p);
}

void command1(int argc, ...)
{
  int i;
  va_list args;
  va_start(args, argc);

  printf("command1\n");

  for(i = 0; i < argc; i++)
  {
    int n;
    n = va_arg(args, int);
    printf("%d\n", n);
  }
  va_end(args);
}


void command2(int argc, ...)
{
  int c;
  int n;
  va_list args;

  printf("command2\n");

  va_start(args, argc);
  c = va_arg(args, int);
  n = va_arg(args, int);
  printf("c:%d n:%d\n", c, n);

  va_end(args);
}

void run(void)
{
  int n;
  struct node_t* _p;

  n = 0;
  for(_p = &root; _p->next != NULL; _p = _p->next)
  {
    if(_p->next != NULL)
    {
      _p->next->cmd(2, n, n * 10);
      n++;
    }
  }
}

void test_command(void)
{
  printf("test_command start\n");
  put(command1);
  put(command2);
  run();
  printf("test_command end\n");
}

int main(int ac, char** av)
{
  test_command();
  return 0;
}
test_command start
command1
0
0
command2
c:1 n:10
test_command end

_ [連結リスト][デザインパターン][Commandパターン][C][優先度]連結リストで優先度あり Command パターン

たんに連結リストの配列にしただけ。0 が優先度高くて、20 が優先度低いです。UNIX 系統の優先度と同じようなもんで。Command というかタスク管理というか。イメージとしては↓のような感じ。実行状態なんてないですが。

zu01_01.gif

(via オリジナルOS「MicrOS」の設計と実装(4) ―― リアルタイム性の確保 )

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>

#define PRI_MAX 20

typedef void (*command_t)(int argc, ...);

struct node_t
{
  struct node_t* next;
  command_t cmd;
} root[PRI_MAX];

/* 先頭に追加 */
void put(int pri, command_t cmd)
{
  int i;
  struct node_t* _p;
  struct node_t* _q;

  for(_p = &root[pri]; _p->next != NULL; _p = _p->next)
    ;

  _q = (struct node_t*)malloc(sizeof(struct node_t));
  if(_q == NULL)
  {
    perror("put");
    exit(0);
  }
  _q->cmd = cmd;
  _q->next = _p->next;
  _p->next = _q;
}

void command0(int argc, ...)
{
  int pri;
  int n;
  va_list args;

  va_start(args, argc);
  pri = va_arg(args, int);
  n = va_arg(args, int);
  printf("command0 pri:%d n:%d\n", pri, n);

  va_end(args);
}

void run(void)
{
  int pri;
  int n;
  struct node_t* _p;

  n = 0;

  for(pri = 0; pri < PRI_MAX; pri++)
  {
    for(_p = &root[pri]; _p->next != NULL; _p = _p->next)
    {
      if(_p->next != NULL)
      {
        _p->next->cmd(2, pri, n);
        n++;
      }
    }
  }
}

void test_command(void)
{
  printf("test_command start\n");
  put(19, command0);
  put(19, command0);
  put(0, command0);
  put(0, command0);
  put(1, command0);
  put(2, command0);
  run();
  printf("test_command end\n");
}

int main(int ac, char** av)
{
  test_command();
  return 0;
}
test_command start
command0 pri:0 n:0
command0 pri:0 n:1
command0 pri:1 n:2
command0 pri:2 n:3
command0 pri:19 n:4
command0 pri:19 n:5
test_command end

_ [艦これ]艦これ

初霜を改造

初雪を改造

山城さんを改造

キラキラ遠征をやってなかったので 6 人をキラキラ状態にして

艦隊決戦援護任務( 15h )行ってきます。

こっちは 4 人キラキラにして

海上護衛任務( 1.5h )行ってきます。