summaryrefslogtreecommitdiffstats
path: root/tools/schedsim/shell/shared/lookup_task.c
blob: 0180886bd9dc25cc52d1913ab0c0043a5e2e0584 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
 *  Given Name or ID String, give Id
 *
 *  COPYRIGHT (c) 1989-2010.
 *  On-Line Applications Research Corporation (OAR).
 *
 *  The license and distribution terms for this file may be
 *  found in the file LICENSE in this distribution or at
 *  http://www.rtems.com/license/LICENSE.
 *
 *  $Id$
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>

#include <rtems.h>
#include <rtems/stringto.h>

#ifndef METHOD_NAME
  #define METHOD_NAME lookup_task
#endif
#ifndef RTEMS_IDENT_NAME
  #define RTEMS_IDENT_NAME rtems_task_ident
#endif

int METHOD_NAME(
  const char *string,
  rtems_id   *id
)
{
  char               name[5];
  rtems_status_code  status;
  unsigned long      tmp;

  if ( string[0] != '0' ) {
    memset( name, '\0', sizeof(name) );
    strncpy( name, string, 4 );
    status = RTEMS_IDENT_NAME( 
      rtems_build_name( name[0], name[1], name[2], name[3] ),
      OBJECTS_SEARCH_ALL_NODES,
      id
    );
    if ( status != RTEMS_SUCCESSFUL )
      return 1;
  } else {
    if ( rtems_string_to_unsigned_long( string, &tmp, NULL, 0) ) {
      fprintf( stderr, "Argument (%s) is not a number\n", string );
      return 1;
    }
    *id = (rtems_id) tmp;
  }

  return 0;
}