Changeset 35d09ba in rtems


Ignore:
Timestamp:
Jul 22, 2009, 3:17:37 PM (10 years ago)
Author:
Joel Sherrill <joel.sherrill@…>
Branches:
4.10, 4.11, master
Children:
f379d80
Parents:
e8d59ca
Message:

2009-07-22 Joel Sherrill <joel.sherrill@…>

  • libmisc/Makefile.am, libmisc/shell/main_chmod.c, libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c, libmisc/shell/main_mfill.c, libmisc/shell/main_mmove.c, libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c, libmisc/shell/main_sleep.c, libmisc/shell/main_umask.c, libmisc/shell/shell.h, libmisc/shell/shell_script.c, libmisc/stringto/stringto_template.h: Convert all shell code to use stringto.h mehods with better error checking.
  • libmisc/shell/str2int.c: Removed.
Location:
cpukit
Files:
1 deleted
14 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    re8d59ca r35d09ba  
     12009-07-22      Joel Sherrill <joel.sherrill@oarcorp.com>
     2
     3        * libmisc/Makefile.am, libmisc/shell/main_chmod.c,
     4        libmisc/shell/main_mdump.c, libmisc/shell/main_medit.c,
     5        libmisc/shell/main_mfill.c, libmisc/shell/main_mmove.c,
     6        libmisc/shell/main_msdosfmt.c, libmisc/shell/main_mwdump.c,
     7        libmisc/shell/main_sleep.c, libmisc/shell/main_umask.c,
     8        libmisc/shell/shell.h, libmisc/shell/shell_script.c,
     9        libmisc/stringto/stringto_template.h: Convert all shell code to use
     10        stringto.h mehods with better error checking.
     11        * libmisc/shell/str2int.c: Removed.
     12
    1132009-07-22      Joel Sherrill <joel.sherrill@oarcorp.com>
    214
  • cpukit/libmisc/Makefile.am

    re8d59ca r35d09ba  
    8181    shell/shell_getprompt.c shell/shellconfig.c \
    8282    shell/shellconfig.h shell/shell.h shell/shell_makeargs.c \
    83     shell/str2int.c shell/filemode.c shell/pwcache.c shell/print-ls.c\
     83    shell/filemode.c shell/pwcache.c shell/print-ls.c \
    8484    shell/write_file.c shell/utils-cp.c  shell/utils-ls.c \
    8585    shell/err.c shell/errx.c shell/verr.c shell/vis.c \
  • cpukit/libmisc/shell/main_chmod.c

    re8d59ca r35d09ba  
    2626#include <rtems.h>
    2727#include <rtems/shell.h>
     28#include <rtems/stringto.h>
    2829#include "internal.h"
    2930
     
    3334)
    3435{
    35   int n;
    36   mode_t mode;
     36  int           n;
     37  mode_t        mode;
     38  unsigned long tmp;
    3739
    38   if (argc > 2) {
    39     mode = rtems_shell_str2int(argv[1]) & 0777;
    40     n = 2;
    41     while (n < argc)
    42       chmod(argv[n++], mode);
     40  if (argc < 2) {
     41    fprintf(stderr,"%s: too few arguments\n", argv[0]);
     42    return -1;
    4343  }
     44
     45  /*
     46   *  Convert arguments into numbers
     47   */
     48  if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     49    printf( "Mode argument (%s) is not a number\n", argv[1] );
     50    return -1;
     51  }
     52  mode = (mode_t) (tmp & 0777);
     53
     54  /*
     55   *  Now change the files modes
     56   */
     57  for (n=2 ; n < argc ; n++)
     58    chmod(argv[n++], mode);
     59
    4460  return 0;
    4561}
  • cpukit/libmisc/shell/main_mdump.c

    re8d59ca r35d09ba  
    2424#include <rtems.h>
    2525#include <rtems/shell.h>
     26#include <rtems/stringto.h>
    2627#include "internal.h"
    27 
    28 /*----------------------------------------------------------------------------*
    29  * RAM MEMORY COMMANDS
    30  *----------------------------------------------------------------------------*/
    3128
    3229int rtems_shell_main_mdump(
     
    3532)
    3633{
    37   unsigned char  n, m;
     34  unsigned long  tmp;
     35  unsigned char  n;
     36  unsigned char  m;
    3837  int            max;
    3938  int            res;
     
    4140  unsigned char *pb;
    4241
    43   if (argc>1)
    44     addr = rtems_shell_str2int(argv[1]);
     42  if (argc > 1) {
     43    if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     44      printf( "Address argument (%s) is not a number\n", argv[1] );
     45      return -1;
     46    }
     47    addr = (uintptr_t) tmp;
     48
     49  }
    4550
    4651  if (argc>2) {
    47     max = rtems_shell_str2int(argv[2]);
     52    if ( !rtems_string_to_int(argv[1], &max, NULL, 0) ) {
     53      printf( "Length argument (%s) is not a number\n", argv[1] );
     54      return -1;
     55    }
     56    addr = (uintptr_t) tmp;
    4857    if (max <= 0) {
    4958      max = 1;      /* print 1 item if 0 or neg. */
     
    6776
    6877  for (m=0; m<max; m++) {
    69     printf("0x%08" PRIXPTR " ", addr);
    7078    pb = (unsigned char*) addr;
     79    printf("%p ", pb);
    7180    for (n=0;n<=(m==(max-1)?res:0xf);n++)
    7281      printf("%02X%c",pb[n],n==7?'-':' ');
  • cpukit/libmisc/shell/main_medit.c

    re8d59ca r35d09ba  
    2323#include <rtems.h>
    2424#include <rtems/shell.h>
     25#include <rtems/stringto.h>
    2526#include "internal.h"
    2627
     
    3233)
    3334{
    34   unsigned char * pb;
    35   int n,i;
     35  unsigned long  tmp;
     36  unsigned char *pb;
     37  int            n;
     38  int            i;
    3639
    37   if (argc<3) {
     40  if ( argc < 3 ) {
    3841    fprintf(stderr,"%s: too few arguments\n", argv[0]);
    3942    return -1;
    4043  }
    4144
    42   pb = (unsigned char*)rtems_shell_str2int(argv[1]);
    43   i = 2;
     45  /*
     46   *  Convert arguments into numbers
     47   */
     48  if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     49    printf( "Address argument (%s) is not a number\n", argv[1] );
     50    return -1;
     51  }
     52  pb = (unsigned char *) tmp;
     53
     54  /*
     55   * Now edit the memory
     56   */
    4457  n = 0;
    45   while (i<=argc) {
    46     pb[n++] = rtems_shell_str2int(argv[i++]) % 0x100;
     58  for (i=2 ; i<=argc ; i++) {
     59    unsigned char tmpc;
     60
     61    if ( !rtems_string_to_unsigned_char(argv[i], &tmpc, NULL, 0) ) {
     62      printf( "Value (%s) is not a number\n", argv[i] );
     63      continue;
     64    }
     65
     66    pb[n++] = tmpc;
    4767  }
    4868
  • cpukit/libmisc/shell/main_mfill.c

    re8d59ca r35d09ba  
    2323#include <rtems.h>
    2424#include <rtems/shell.h>
     25#include <rtems/stringto.h>
    2526#include "internal.h"
    2627
     
    3031)
    3132{
     33  unsigned long tmp;
    3234  uintptr_t     addr;
    3335  size_t        size;
     
    3941  }
    4042
    41   addr  = rtems_shell_str2int(argv[1]);
    42   size  = rtems_shell_str2int(argv[2]);
    43   value = rtems_shell_str2int(argv[3]) % 0x100;
    44   memset((unsigned char*)addr,size,value);
     43  /*
     44   *  Convert arguments into numbers
     45   */
     46  if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     47    printf( "Address argument (%s) is not a number\n", argv[1] );
     48    return -1;
     49  }
     50  addr = (uintptr_t) tmp;
     51
     52  if ( !rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
     53    printf( "Size argument (%s) is not a number\n", argv[2] );
     54    return -1;
     55  }
     56  size = (size_t) tmp;
     57
     58  if ( !rtems_string_to_unsigned_char(argv[3], &value, NULL, 0) ) {
     59    printf( "Value argument (%s) is not a number\n", argv[3] );
     60    return -1;
     61  }
     62
     63  /*
     64   *  Now fill the memory.
     65   */
     66  memset((unsigned char*)addr, size, value);
    4567
    4668  return 0;
  • cpukit/libmisc/shell/main_mmove.c

    re8d59ca r35d09ba  
    2323#include <rtems.h>
    2424#include <rtems/shell.h>
     25#include <rtems/stringto.h>
    2526#include "internal.h"
    2627
     
    3233)
    3334{
    34  uintptr_t  src;
    35  uintptr_t  dst;
    36  size_t     length;
     35  unsigned long tmp;
     36  uintptr_t     src;
     37  uintptr_t     dst;
     38  size_t        length;
    3739
    38  if ( argc<4 ) {
    39   fprintf(stderr,"%s: too few arguments\n", argv[0]);
    40   return -1;
    41  }
     40  if ( argc < 4 ) {
     41    fprintf(stderr,"%s: too few arguments\n", argv[0]);
     42    return -1;
     43   }
    4244
    43  dst    = rtems_shell_str2int(argv[1]);
    44  src    = rtems_shell_str2int(argv[2]);
    45  length = rtems_shell_str2int(argv[3]);
    46  memcpy((unsigned char*)dst, (unsigned char*)src, length);
     45  /*
     46   *  Convert arguments into numbers
     47   */
     48  if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     49    printf( "Destination argument (%s) is not a number\n", argv[1] );
     50    return -1;
     51  }
     52  dst = (uintptr_t) tmp;
     53
     54  if ( !rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
     55    printf( "Source argument (%s) is not a number\n", argv[2] );
     56    return -1;
     57  }
     58  src = (uintptr_t) tmp;
     59
     60  if ( !rtems_string_to_unsigned_long(argv[3], &tmp, NULL, 0) ) {
     61    printf( "Length argument (%s) is not a number\n", argv[3] );
     62    return -1;
     63  }
     64  length = (size_t) tmp;
     65
     66  /*
     67   *  Now copy the memory.
     68   */
     69  memcpy((unsigned char*)dst, (unsigned char*)src, length);
    4770
    4871 return 0;
  • cpukit/libmisc/shell/main_msdosfmt.c

    re8d59ca r35d09ba  
    11/*
    2  *   Shell Command Implmentation
    3  *
    4  *  Author: Fernando RUIZ CASAS
    5  *  Work: fernando.ruiz@ctv.es
    6  *  Home: correo@fernando-ruiz.com
    7  *
    82 *  The license and distribution terms for this file may be
    93 *  found in the file LICENSE in this distribution or at
     
    2418#include <rtems.h>
    2519#include <rtems/shell.h>
     20#include <rtems/stringto.h>
    2621#include <rtems/shellconfig.h>
    2722#include <rtems/dosfs.h>
     
    4742  };
    4843 
    49   const char* driver = NULL;
    50   int         arg;
     44  unsigned long tmp;
     45  const char*   driver = NULL;
     46  int           arg;
    5147 
    5248  for (arg = 1; arg < argc; arg++) {
     
    6864            return 1;
    6965          }
    70           rqdata.sectors_per_cluster = rtems_shell_str2int(argv[arg]);
     66
     67          if ( !rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
     68            printf(
     69              "sector per cluster argument (%s) is not a number\n",
     70               argv[arg]
     71            );
     72            return -1;
     73          }
     74
     75          rqdata.sectors_per_cluster = (uint32_t) tmp;
    7176          break;
    7277         
     
    7782            return 1;
    7883          }
    79           rqdata.files_per_root_dir = rtems_shell_str2int(argv[arg]);
     84
     85          if ( !rtems_string_to_unsigned_long(argv[arg], &tmp, NULL, 0) ) {
     86            printf(
     87              "root directory size argument (%s) is not a number\n",
     88               argv[arg]
     89            );
     90            return -1;
     91          }
     92
     93          rqdata.files_per_root_dir = (uint32_t) tmp;
    8094          break;
    8195         
  • cpukit/libmisc/shell/main_mwdump.c

    re8d59ca r35d09ba  
    2424#include <rtems.h>
    2525#include <rtems/shell.h>
     26#include <rtems/stringto.h>
    2627#include "internal.h"
    2728
     
    3132)
    3233{
    33   unsigned char  n, m;
     34  unsigned long  tmp;
     35  unsigned char  n;
     36  unsigned char  m;
    3437  int            max;
    3538  int            res;
     
    3740  unsigned char *pb;
    3841
    39   if (argc>1)
    40     addr = rtems_shell_str2int(argv[1]);
     42  if ( argc > 1 ) {
     43    if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     44      printf( "Address argument (%s) is not a number\n", argv[1] );
     45      return -1;
     46    }
     47    addr = (uintptr_t) tmp;
     48  }
    4149
    42   if (argc>2) {
    43     max = rtems_shell_str2int(argv[2]);
     50  if ( argc > 2 ) {
     51    if ( !rtems_string_to_int(argv[2], &max, NULL, 0) ) {
     52      printf( "Address argument (%s) is not a number\n", argv[1] );
     53      return -1;
     54    }
     55
    4456    if (max <= 0) {
    4557      max = 1;      /* print 1 item if 0 or neg. */
    4658      res = 0;
    47     }
    48     else {
     59    } else {
    4960      max--;
    5061      res = max & 0xf;/* num bytes in last row */
     
    5667      }
    5768    }
    58   }
    59   else {
     69  } else {
    6070    max = 20;
    6171    res = 0xf;
     
    6373
    6474  for (m=0;m<max;m++) {
    65     printf("0x%08" PRIXPTR " ",addr);
    6675    pb = (unsigned char *) addr;
     76    printf("%p ", pb);
    6777    for (n=0;n<=(m==(max-1)?res:0xf);n+=2)
    6878      printf("%04X%c",*((unsigned short*)(pb+n)),n==6?'-':' ');
  • cpukit/libmisc/shell/main_sleep.c

    re8d59ca r35d09ba  
    2121#include <rtems.h>
    2222#include <rtems/shell.h>
     23#include <rtems/stringto.h>
    2324#include "internal.h"
    2425
     
    2930{
    3031  struct timespec delay;
     32  unsigned long   tmp;
    3133
    32   if (argc == 2) {
    33     delay.tv_sec = rtems_shell_str2int(argv[1]);
    34     delay.tv_nsec = 0;
    35     nanosleep( &delay, NULL );
    36     return 0;
     34  if ((argc != 2) && (argc != 3)) {
     35    fprintf( stderr, "%s: Usage seconds [nanoseconds]\n", argv[0] );
     36    return -1;
    3737  }
    38  
     38
     39  /*
     40   *  Convert the seconds argument to a number
     41   */
     42  if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     43    printf( "Seconds argument (%s) is not a number\n", argv[1] );
     44    return -1;
     45  }
     46  delay.tv_sec = (time_t) tmp;
     47
     48  /*
     49   *  If the user specified a nanoseconds argument, convert it
     50   */
     51  delay.tv_nsec = 0;
    3952  if (argc == 3) {
    40     delay.tv_sec = rtems_shell_str2int(argv[1]);
    41     delay.tv_nsec = rtems_shell_str2int(argv[2]);
    42     nanosleep( &delay, NULL );
    43     return 0;
     53    if ( !rtems_string_to_unsigned_long(argv[2], &tmp, NULL, 0) ) {
     54      printf( "Seconds argument (%s) is not a number\n", argv[1] );
     55      return -1;
     56    }
     57    delay.tv_nsec = tmp;
    4458  }
    45  
    46   fprintf( stderr, "%s: Usage seconds [nanoseconds]\n", argv[0] );
    47   return -1;
     59
     60  /*
     61   *  Now sleep as requested.
     62   */
     63  nanosleep( &delay, NULL );
     64  return 0;
    4865}
    4966
  • cpukit/libmisc/shell/main_umask.c

    re8d59ca r35d09ba  
    2626#include <rtems.h>
    2727#include <rtems/shell.h>
     28#include <rtems/stringto.h>
    2829#include "internal.h"
    2930
     
    3334)
    3435{
    35   mode_t msk = umask(0);
     36  unsigned long tmp;
     37  mode_t        msk = umask(0);
    3638
    37   if (argc == 2)
    38     msk = rtems_shell_str2int(argv[1]);
     39  if (argc == 2) {
     40    if ( !rtems_string_to_unsigned_long(argv[1], &tmp, NULL, 0) ) {
     41      printf( "Mask argument (%s) is not a number\n", argv[1] );
     42      return -1;
     43    }
     44    msk = (mode_t) tmp;
     45
     46  }
    3947  umask(msk);
    4048
  • cpukit/libmisc/shell/shell.h

    re8d59ca r35d09ba  
    184184);
    185185
    186 /*
    187  *  Things that are useful to external entities developing commands and plugging
    188  *  them in.
    189  */
    190 int rtems_shell_str2int(const char * s);
    191 
     186/**
     187 *  Private environment associated with each shell instance.
     188 */
    192189typedef struct {
    193   rtems_name magic; /* 'S','E','N','V': Shell Environment */
     190  /** 'S','E','N','V': Shell Environment */
     191  rtems_name magic;
    194192  const char *devname;
    195193  const char *taskname;
    196   /* user extensions */
    197194  bool exit_shell; /* logout */
    198195  bool forever; /* repeat login */
    199196  int errorlevel;
    200197  bool echo;
    201   char cwd [256];
     198  char cwd[256];
    202199  const char *input;
    203200  const char *output;
  • cpukit/libmisc/shell/shell_script.c

    re8d59ca r35d09ba  
    3131#include <rtems.h>
    3232#include <rtems/shell.h>
     33#include <rtems/stringto.h>
    3334#include "internal.h"
    3435
     
    108109)
    109110{
     111  unsigned long        tmp;
    110112  int                  option;
    111113  int                  sc;
     
    125127        outputFile = getopt_reent.optarg;
    126128        break;
    127       case 'p':
    128         taskPriority =
    129           (rtems_task_priority) rtems_shell_str2int(getopt_reent.optarg);
    130         break;
    131       case 's':
    132         stackSize = (uint32_t) rtems_shell_str2int(getopt_reent.optarg);
    133         break;
     129      case 'p': {
     130        const char *s = getopt_reent.optarg;
     131
     132        if ( !rtems_string_to_unsigned_long( s, &tmp, NULL, 0) ) {
     133          printf( "Task Priority argument (%s) is not a number\n", s );
     134          return -1;
     135        }
     136        taskPriority = (rtems_task_priority) tmp;
     137        break;
     138      }
     139      case 's': {
     140        const char *s = getopt_reent.optarg;
     141
     142        if ( !rtems_string_to_unsigned_long( s, &tmp, NULL, 0) ) {
     143          printf( "Stack size argument (%s) is not a number\n", s );
     144          return -1;
     145        }
     146        stackSize = (uint32_t) tmp;
     147        break;
     148      }
    134149      case 't':
    135150        taskName = getopt_reent.optarg;
  • cpukit/libmisc/stringto/stringto_template.h

    re8d59ca r35d09ba  
    102102  #endif
    103103
    104   *n = result;
     104  *n = (STRING_TO_TYPE) result;
    105105  return true;
    106106}
Note: See TracChangeset for help on using the changeset viewer.