2 * This file has been modified for the cdrkit suite.
4 * The behaviour and appearence of the program code below can differ to a major
5 * extent from the version distributed by the original author(s).
7 * For details, see Changelog file distributed with the cdrkit package. If you
8 * received this file from another source then ask the distributing person for
9 * a log of modifications.
13 /* @(#)getnum.c 1.2 04/03/02 Copyright 1984-2002, 2004 J. Schilling */
15 * Number conversion routines to implement 'dd' like options.
17 * Copyright (c) 1984-2002, 2004 J. Schilling
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License version 2
22 * as published by the Free Software Foundation.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License along with
30 * this program; see the file COPYING. If not, write to the Free Software
31 * Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
39 static Llong number(char *arg, int *retp);
40 int getnum(char *arg, long *valp);
41 int getllnum(char *arg, Llong *lvalp);
44 number(register char *arg, int *retp)
52 } else if (*(arg = astoll(arg, &val))) {
53 if (*arg == 'p' || *arg == 'P') {
55 val *= (1024*1024*1024);
58 } else if (*arg == 't' || *arg == 'T') {
63 } else if (*arg == 'g' || *arg == 'G') {
64 val *= (1024*1024*1024);
67 } else if (*arg == 'm' || *arg == 'M') {
71 } else if (*arg == 'f' || *arg == 'F') {
75 } else if (*arg == 's' || *arg == 'S') {
79 } else if (*arg == 'k' || *arg == 'K') {
83 } else if (*arg == 'b' || *arg == 'B') {
87 } else if (*arg == 'w' || *arg == 'W') {
91 if (*arg == '*' || *arg == 'x')
92 val *= number(++arg, retp);
93 else if (*arg != '\0')
100 getnum(char *arg, long *valp)
105 llval = number(arg, &ret);
107 if (*valp != llval) {
109 "Value %lld is too large for data type 'long'.\n",
117 getllnum(char *arg, Llong *lvalp)
121 *lvalp = number(arg, &ret);