Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Need to replace SASC memxlt() and xltable() function

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics
View previous topic :: :: View next topic  
Author Message
selvamsrinivasan85

New User


Joined: 09 Aug 2010
Posts: 16
Location: Coimbatore

PostPosted: Mon Nov 15, 2010 11:07 pm    Post subject: Need to replace SASC memxlt() and xltable() function
Reply with quote

Hello friends,

I am in a need of creating a String function that has to replace SASC predefined memxlt() and xltable() functions.

Description:
memxlt() -
void *memxlt(void *blk, const char *table, size_t n);

- memxlt translates a block of memory from one character set to another. The first argument ( blk ) is the address of the area of memory to be translated, and the third argument ( n ) is the number of characters to be translated. The second argument ( table ) is a pointer to a 256-byte translate table, which should be defined so that table[c] for any character c is the value to which c should be translated. (The function xltable is frequently used to build such a table.)

Note:
The argument string is translated in place; that is, each character in the string is replaced by a translated character.

Return value:
memxlt returns a pointer to the translated string.

Caution:
The third argument to memxlt is size_t . If a negative number is passed, massive overlaying of memory occurs.
The effect of memxlt is not defined if the source string and the translate table overlap.

e.g:

Code:
#include <lcstring.h>
#include <stdio.h>
#include <stdlib.h>
main(int argc, char *argv[])
{
int len, i, j;
char a;
char alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char table[256];
if (argc < 2) {
puts("Specify the secret word on the command line.");
exit(4);
}
len = strlen(argv[1] );
memupr(argv[1], len); /* Uppercase input message. */
/* Randomize the alphabet. */
for (i = 0; i < 26; i++)
for (j = i + 1; j < 26; j++)
if (rand() % 2) {
a = alphabet[i];
alphabet[i] = alphabet[j] ;
alphabet[j] = a;
}
/* Build a translate table. */
xltable(table,"ABCDEFGHIJKLMNOPQRSTUVWXYZ",alphabet);
/* Translate message. */
memxlt(argv[1],table,len);
/* Print message. */
printf("Today's secret word is: \n%s\n",argv[1]);
return;
}


xltable() -
char *xltable(char table[256], char *source, char *target);

Description:
xltable builds a translation table that you can use later as an argument to the memxlt or strxlt function.
The argument table is a 256-character array, in which the translation table is to be built. The second argument ( source ) is a string of characters that the table is to translate, and the third argument ( target ) is a string containing the characters to which the source characters are to be translated, in the same order. The source and target strings should contain the same number of characters; if they do not, the extra characters of the longer string are ignored.
You can also specify a table address of 0. In this case, xltable builds the table in a static area and returns the address of this area. This area may be overlaid by the next call to xltable , strscntb , or memscntb .
The table built by xltable translates any character not present in the source string to itself, so these characters are not changed when using the table.

Please let me know if you need any more details.
Back to top
View user's profile Send private message

PeterHolland

Global Moderator


Joined: 27 Oct 2009
Posts: 2429
Location: Netherlands, Amstelveen

PostPosted: Mon Nov 15, 2010 11:11 pm    Post subject:
Reply with quote

And the question is ?
Back to top
View user's profile Send private message
selvamsrinivasan85

New User


Joined: 09 Aug 2010
Posts: 16
Location: Coimbatore

PostPosted: Mon Nov 15, 2010 11:17 pm    Post subject: Reply to: Need to replace SASC memxlt() and xltable() functi
Reply with quote

Hi,

The question is can anyone help to create a user-defined C function for the above pre-defined SASC functions, as we replacing a SASC compiler with IBM/C compiler.
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10231
Location: italy

PostPosted: Mon Nov 15, 2010 11:26 pm    Post subject: Reply to: Need to replace SASC memxlt() and xltable() functi
Reply with quote

what kind of help ??

where are You facing issues...
the coding or the logic?

neither looks overly complicated to my warped mind
Back to top
View user's profile Send private message
selvamsrinivasan85

New User


Joined: 09 Aug 2010
Posts: 16
Location: Coimbatore

PostPosted: Mon Nov 15, 2010 11:46 pm    Post subject: Reply to: Need to replace SASC memxlt() and xltable() functi
Reply with quote

Hi enrico,

We have coded functions for replacing those SASC built-in functions. the issue we are facing is only one line is getting printed on the file.

For e.g, SASC compiler run has below format of output
1C2AACD201010010802001 - Header Info.
1C2AACDNYRG0001 - Trailer Info
....
1C2AACDNYRG9999 - Trailer Info

But using IBM/C compiler, we are getting only header info.

Code is given below for your reference,

char_map replaces the SASC function xltable:
*********************************************
char *char_map(char tableÝ256¨ , char *source, char *target) {
char *new_table = table; /* Pointer to the table we are returning *
char *tgt; /* Pointer to where the target data starts */
int i;

/* Initialize the array we are returning with standard ascii */
for (i = 0; i < 256; i++)
new_tableÝi¨ = i % 128;
/* The middle of the Array is where we keep target */
tgt = &new_tableÝ128¨ ;

/* Store the data that was passed in to our new table until one
(or both) of the string(s) end(s) */
while (*source != '\0' && *target != '\0') {
tgtÝ*source¨ = * target;
source++;
target++;
}

return new_table;
}

char_trans replaces the SASC function memxlt:
*********************************************
char *char_trans(void *blk, const char *table, size_t n) {
char *ret_val = blk;
int i;
int tmp=0;

for (i = 0; i < n; i++) {
tmp = ret_valÝi¨ + 128;
ret_valÝi¨ = tableÝtmp¨ ;
}

return ret_val;
}
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10231
Location: italy

PostPosted: Tue Nov 16, 2010 12:22 am    Post subject: Reply to: Need to replace SASC memxlt() and xltable() functi
Reply with quote

the last post was completely obfuscated by the char translation

frankly I do not see how a <wrong> translate might result in a missing record

also the terminology is confusing...

since I was not able to understand anything I found simpler to rewrite everything from scratch
Code:


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

#define XTSIZE 256
char * xtable(unsigned char *tb, unsigned char *in, unsigned char *ou)
{
int i;
   if   ( strlen(in) != strlen(ou) )
      return NULL ;
   for ( i = 0; i < XTSIZE; i++)
      tb[i] = (unsigned char) i;
   for ( i = 0; i < strlen(in); i++)
      tb[in[i]] = ou[i] ;
   return tb;
}

void * xlate(unsigned char *in, unsigned char *tb, int l)
{
int i;
   for ( i = 0; i < l; i++)
      in[i] = tb[in[i]] ;
   return in ;
}

main(int argc, char **argv)
{
unsigned char tb[XTSIZE] ;
unsigned char in[] = "ABCDEFG" ;

   if   ( xtable(tb,"ABCDEFG","abcdefg") )
   {
      printf("table build success\n");
      printf("before ==>%s<==\n",in);
      if ( xlate(in,tb,strlen(in) ) )
      {
         printf("xlate success\n");
         printf("after  ==>%s<==\n",in);
      }
      else
         printf("xlate failure\n");
   }
   else
      printf("table build failure\n");

}


TESTED AND WORKING
Back to top
View user's profile Send private message
selvamsrinivasan85

New User


Joined: 09 Aug 2010
Posts: 16
Location: Coimbatore

PostPosted: Tue Nov 16, 2010 1:41 am    Post subject: Reply to: Need to replace SASC memxlt() and xltable() functi
Reply with quote

Hi enrico,

Thanks for the help. But still facing the same issue icon_sad.gif(Only header records are printing correctly) .
Back to top
View user's profile Send private message
enrico-sorichetti

Global Moderator


Joined: 14 Mar 2007
Posts: 10231
Location: italy

PostPosted: Tue Nov 16, 2010 1:44 am    Post subject: Reply to: Need to replace SASC memxlt() and xltable() functi
Reply with quote

as I said before it is hard to believe that it could be a translate issue
( if the translate stuff has been reasonably tested )
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> All Other Mainframe Topics All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Check System time(Minute) Using TIME1... balaji81_k DFSORT/ICETOOL 5 Fri Nov 11, 2016 10:53 am
No new posts Replace repeated JCL with looping REXX prino CLIST & REXX 3 Thu Oct 13, 2016 5:30 am
No new posts Strange EXEC function call in z/VM Willy Jensen CLIST & REXX 3 Wed Oct 05, 2016 2:07 pm
This topic is locked: you cannot edit posts or make replies. Sort card to replace text using cross... Susanta SYNCSORT 32 Tue Sep 13, 2016 4:17 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us