- 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;
}
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.
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.
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¨ ;
}