2 * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc., 59
21 * Temple Place - Suite 330, Boston MA 02111-1307, USA.
23 * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
24 * Mountain View, CA 94043, or:
28 * For further information regarding this notice, see:
30 * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
34 #include "dataascii.h"
36 #define CHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghjiklmnopqrstuvwxyz\n"
37 #define CHARS_SIZE sizeof(CHARS)
40 #include <stdlib.h> /* malloc */
43 static char Errmsg[80];
46 dataasciigen(listofchars, buffer, bsize, offset)
47 char *listofchars; /* a null terminated list of characters */
54 int ind; /* index into CHARS array */
62 if ( listofchars == NULL ) {
64 chars_size=CHARS_SIZE;
68 chars_size=strlen(listofchars);
71 for(cnt=offset; cnt<total; cnt++) {
78 } /* end of dataasciigen */
81 dataasciichk(listofchars, buffer, bsize, offset, errmsg)
82 char *listofchars; /* a null terminated list of characters */
90 int ind; /* index into CHARS array */
98 if ( listofchars == NULL ) {
100 chars_size=CHARS_SIZE;
103 charlist=listofchars;
104 chars_size=strlen(listofchars);
107 if ( errmsg != NULL ) {
111 for(cnt=offset; cnt<total; chr++, cnt++) {
113 if ( *chr != charlist[ind] ) {
115 "data mismatch at offset %d, exp:%#o, act:%#o", cnt,
116 charlist[ind], *chr);
121 sprintf(Errmsg, "all %d bytes match desired pattern", bsize);
122 return -1; /* buffer is ok */
124 } /* end of dataasciichk */
129 /***********************************************************************
130 * main for doing unit testing
131 ***********************************************************************/
143 if ((buffer=(char *)malloc(size)) == NULL ) {
148 dataasciigen(NULL, buffer, size, 0);
149 printf("dataasciigen(NULL, buffer, %d, 0)\n", size);
151 ret=dataasciichk(NULL, buffer, size, 0, &errmsg);
152 printf("dataasciichk(NULL, buffer, %d, 0, &errmsg) returned %d %s\n",
156 printf("\tPASS return value is -1 as expected\n");
158 printf("\tFAIL return value is %d, expected -1\n", ret);
160 ret=dataasciichk(NULL, &buffer[1], size-1, 1, &errmsg);
161 printf("dataasciichk(NULL, &buffer[1], %d, 1, &errmsg) returned %d %s\n",
162 size-1, ret, errmsg);
165 printf("\tPASS return value is -1 as expected\n");
167 printf("\tFAIL return value is %d, expected -1\n", ret);
170 printf("changing char 25\n");
172 ret=dataasciichk(NULL, &buffer[1], size-1, 1, &errmsg);
173 printf("dataasciichk(NULL, &buffer[1], %d, 1, &errmsg) returned %d %s\n",
174 size-1, ret, errmsg);
177 printf("\tPASS return value is 25 as expected\n");
179 printf("\tFAIL return value is %d, expected 25\n", ret);
181 dataasciigen("this is a test of the my string" , buffer, size, 0);
182 printf("dataasciigen(\"this is a test of the my string\", buffer, %d, 0)\n", size);
184 ret=dataasciichk("this is a test of the my string", buffer, size, 0, &errmsg);
185 printf("dataasciichk(\"this is a test of the my string\", buffer, %d, 0, &errmsg) returned %d %s\n",
189 printf("\tPASS return value is -1 as expected\n");
191 printf("\tFAIL return value is %d, expected -1\n", ret);
193 ret=dataasciichk("this is a test of the my string", &buffer[1], size-1, 1, &errmsg);
194 printf("dataasciichk(\"this is a test of the my string\", &buffer[1], %d, 1, &errmsg) returned %d %s\n",
195 size-1, ret, errmsg);
198 printf("\tPASS return value is -1 as expected\n");
200 printf("\tFAIL return value is %d, expected -1\n", ret);
203 printf("changing char 25\n");
205 ret=dataasciichk("this is a test of the my string", &buffer[1], size-1, 1, &errmsg);
206 printf("dataasciichk(\"this is a test of the my string\", &buffer[1], %d, 1, &errmsg) returned %d %s\n",
207 size-1, ret, errmsg);
210 printf("\tPASS return value is 25 as expected\n");
212 printf("\tFAIL return value is %d, expected 25\n", ret);