Author Topic: Rexx -> IBM C  (Read 14493 times)

xynixme

  • Guest
Re: Rexx -> IBM C
« Reply #15 on: October 26, 2018, 04:22:15 pm »
help chcp

And check the settings notebook of any program. Here there is a page named 'Sprache'.

Please do not change your codepage setting in your config.sys.

Well spotted. Einverstanden. CONFIG.SYS would have been my first weapon of choice, because here this setting is always the default.

I did remember CHCP somehow, while not using OS/2 at the moment, but did't think of its HELP. Thanks.

Bogdan

  • Jr. Member
  • **
  • Posts: 93
  • Karma: +1/-0
    • View Profile
Re: Rexx -> IBM C
« Reply #16 on: October 26, 2018, 08:52:37 pm »
1. I cannot check my OS-2 CODEPAGE setting right now, but the default is 850. Does 850,437 mean that I can swap at the OS level (STDOUT, et cetera) to 437 , while an app may use e.g. 860 "internally"?
No

Quote
2. Do all systems have a 850 by default?
No
Quote
IOW, would a Portugese OS/2 version have the setting 860,850? Portugese by default, with the international 850 as an option? Or reversed, 850,860.
It depends on which Portuguese language version is used. In doubt DosQueryCp should answer correctly.

xynixme

  • Guest
Re: Rexx -> IBM C
« Reply #17 on: October 31, 2018, 05:44:37 am »
Quote
IOW, would a Portugese OS/2 version have the setting 860,850? Portugese by default, with the international 850 as an option? Or reversed, 850,860.

It depends on which Portuguese language version is used. In doubt DosQueryCp should answer correctly.

Fortunately codepage 860 is one of the codepages which can be used, because the relevant characters are identical. I still have to look at the APIs you've mentioned earlier. I did RTFM, but it's not that obvious how it works.

Avoiding the superscript 1, 2 & 3 is implemented now. Those characters often are different/missing. Previously a superscript 1 was appended to a name and converted to "¹", but now this is a suffix (inside the same struct as the nme) which is "\0" or "¹\0".

I've seen that even the "&" isn't always the same character per codepage, so I may need the APIs anyway. Homework... No programming guide, and no clear output of sample code...

xynixme

  • Guest
Re: Rexx -> IBM C
« Reply #18 on: November 03, 2018, 07:14:21 pm »
I'v decided to not embed UCONV now, because it introduces more problems that it will solve. Like a HTLMNAME.DLL, which could be the prefered solution. After all I'm not writing a single, generic TXT2HTML.EXE.

It's not that simple, for one because e.g. http://www.edm2.com/index.php/UniCreateUconvObject produces quite a few return codes instead of clear output.

Of course I will keep it in mind. And I've reduced the number of high-ASCII characters which are too rare. An appended "¹"is no longer being converted to "¹" as part of a name. Instead the name is converted, and next "¹" is appended.

xynixme

  • Guest
Re: Rexx -> IBM C
« Reply #19 on: November 05, 2018, 12:03:23 pm »
I'v decided to not embed UCONV now, because it introduces more problems that it will solve. Like a HTLMNAME.DLL, which could be the prefered solution. After all I'm not writing a single, generic TXT2HTML.EXE.

Below is a test version of the code I'll use in one of the existing data file verification steps.

According to the documentation of DosSetProcessCp() the number of implied supported codepages is 6. If the current codepage is not supported, then it prints a warning. If an installed (CODEPAGE=xxx,yyy] codepage is supported, then it suggests to switch codepages when needed. If none of the installed codepages is supported , then it prints a list of supported codepages. Which doesn't really help an user, but that's a rather theoretical situation anyway because th euser will be somehow mixing foreign and native words anyway.

The code itself is not that useful, and should be basic stuff for experienced programmers. The main progress is that using a specific codepage, Rexx won't be aware of any, is no longer assumed.

Code: [Select]
#define INCL_DOSERRORS
#define INCL_DOSNLS
#define CODEPAGES 6

#include <os2.h>
#include <stdio.h>

int main(void)
{
APIRET rc=NO_ERROR;
ULONG aulCpList[8]={0},codepages[CODEPAGES]={437,850,857,860,861,865},found=0,i,j,ulBufSize=8*sizeof(ULONG),ulListSize=0;

rc=DosQueryCp(ulBufSize,aulCpList,&ulListSize);
if (rc==NO_ERROR)
   {
   aulCpList[0];
   for (i=0;i<CODEPAGES;i++)   
      if (codepages[i]==aulCpList[0])
         found=1;
   if (!found)
      {
      printf("Warning: codepage %u is not supported.\n",aulCpList[0]);
      for (i=0;i<ulListSize/sizeof(ULONG);i++)
         if (aulCpList[i]!=aulCpList[0])
            {
            found=99999;
            for (j=0;j<CODEPAGES;j++)   
               if (aulCpList[i]==codepages[j])
                  found=j;
            if (found!=99999)
               printf("Execute the OS/2 command \"CHCP %u\" before creating or editing data files.\n",codepages[found]);
            else
               {
               printf("Supported codepages are:\n\n");
               for (j=0;j<CODEPAGES;j++)
                  printf("%u\n",codepages[j]);   
               }
            }
      }
   }

return 0;
}


xynixme

  • Guest
Re: Rexx -> IBM C
« Reply #20 on: December 03, 2018, 07:49:00 pm »
Same code review request, to not learn anything bad. Again, Rexx ported to C. The code works, and creates a Metastock PRN file after importing individual HTML files.

The business end is in the large for-loop.

Please ignore the error texts, I know I'm reusing the date variable, I'm using DosForceDelete intentionally, and as far as I know the code works, albeit translation may have introduced an error.

Main data formats are &pound;123,45, 123.456 or e.g. $1.2345. Data doesn't have to be checked. I don't know if I have processed Rexx' PARSEs correctly, and it's the first time I've used pointers this way without copying existing code.


Code: [Select]
/* Import.C */

#define INCL_DOSDATETIME
#define INCL_DOSFILEMGR

#include <ctype.h>
#include <io.h>
#include <os2.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUFLEN 8192
#define INDEX1 "PSI20\0"
#define MAXRECORDS 768
#define LINELEN 128


typedef struct _RECORDS {char symbol[11];} RECORDS;


int main(void)
{
BOOL found=0;
char *all,sourcename[CCHMAXPATH],day,*data,date[LINELEN],targetname[LINELEN],dummy[2],high[16],low[16],month,open[16],*orgdata,*skipped,prefix[16],line[LINELEN],suffix[16],volume[16];
DATETIME dt;
FILE *source,*target;
RECORDS *records;
ULONG date2,today;
USHORT done=0,i,year,counter=0,counter2,counter3=0;

DosGetDateTime(&dt);
today=dt.year*10000+dt.month*100+dt.day;

if (dt.hours*60+dt.minutes<1105)
   {
   sprintf(sourcename,"%08u.001",today);
   if (!access(sourcename,00))
       {
       printf("\Error\n");
       return 1;
       }
   dt.day--;
   if (!dt.day)
      {
      dt.day=31;
      dt.month--;
      if (!dt.month)
         {
         dt.month=12;
         dt.year--;
         }
      if (dt.month==4||dt.month==6||dt.month==9||dt.month==11)
         dt.day--;
      else if (dt.month==2)
         {
         dt.day=28;
         if (!dt.year%4&&dt.year%100)
            dt.day++;
         }
      }
   today=dt.year*10000+dt.month*100+dt.day;
   sprintf(sourcename,"%08u.001",today);
   if (-1==access(sourcename,00))
       {
       printf("\nError\n");
       return 1;
       }
   }

if (NULL==(records=calloc(MAXRECORDS,sizeof(RECORDS))))
   {
   printf("\nError\n");
   return 1;
   }

sprintf(sourcename,"AANDELEN.LST");
if ((source=fopen(sourcename,"r"))==NULL)
   {
   printf("\nError\n",sourcename);
   free(records);
   return 1;
   }
while (NULL!=fgets(line,LINELEN,source))
   {
   sscanf(line,"%10c",records[0].symbol);
   records[0].symbol[10]=0;
   while (strlen(records[0].symbol)&&isblank(records[0].symbol[strlen(records[0].symbol)-1]))
      records[0].symbol[strlen(records[0].symbol)-1]=0;
   if (strlen(records[0].symbol))
      strcpy(records[++counter].symbol,records[0].symbol);
   }
fclose(source);

if (!counter)
   {
   printf("\nError\n",sourcename);
   free(records);
   return 1;
   }
for (i=1;i<=counter;i++)
   if (!strcmp(records[i].symbol,INDEX1))
      {
      found=1;
      i=counter;
      }
if (!found)
   {
   printf("\nError\n",INDEX1,sourcename);
   free(records);
   return 1;
   }

strcpy(sourcename,INDEX1);
if (-1==access(sourcename,00))
   {
   printf("\nError\n",sourcename);
   free(records);
   return 1;
   }

if (NULL==(skipped=calloc(BUFLEN,sizeof(char))))
   {
   printf("\nError\n");
   free(records);
   return 1;
   }
if (NULL==(all=calloc(BUFLEN,sizeof(char))))
   {
   printf("\nError\n");
   free(records);
   free(skipped);
   return 1;
   }
if (NULL==(data=calloc(BUFLEN,sizeof(char))))
   {
   printf("\nError\n");
   free(all);
   free(records);
   free(skipped);
   return 1;
   }
orgdata=data;

sprintf(targetname,"%04u.PRN",dt.year);
if (-1==access(targetname,00))
   found=0;
if ((target=fopen(targetname,"a"))==NULL)
   {
   printf("\nError\n",targetname);
   free(all);
   free(data);
   free(records);
   free(skipped);
   return 1;
   }
if (!found)
   {
   fprintf(target,"<TICKER>,<PER>,<DTYYYYMMDD>,<OPEN>,<HIGH>,<LOW>,<CLOSE>,<VOL>,<OI>\n");
   printf("\nFile %s created.\n\n",targetname);
   }

for (i=1;i<=counter;i++)
   {
   if ((source=fopen(records[i].symbol,"rb"))==NULL)
      {
      printf("\nError\n");
      fclose(target);
      free(all);
      free(data);
      free(records);
      free(skipped);
      return 1;
      }
   fread(all,sizeof(char),BUFLEN,source);
   fclose(source);
   sprintf(date,"id=\"datetimeLastvalue\">\0");
   data=strstr(all,date);
   data+=strlen(date);
   day=(*data-'0')*10;
   data++;
   day+=*data-'0';
   data+=2;
   month=(*data-'0')*10;
   data++;   
   month+=*data-'0';
   data+=2;
   year=(*data-'0')*1000;
   data++;   
   year+=(*data-'0')*100;
   data++;   
   year+=(*data-'0')*10;
   data++;   
   year+=*data-'0';
   date2=year*10000+month*100+day;   
   if (date2!=today)   
      printf("No data found: %s\n",records[i].symbol);
   else
      {
      sprintf(date,"id=\"lastPriceint\">\0");
      if (NULL!=(data=strstr(all,date)))
         {
         data+=strlen(date);
         counter2=0;
         while (isdigit(*data))
            {
            prefix[counter2++]=*data;         
            *data++;
            }
         prefix[counter2]=0;
         counter2=0;
         sprintf(date,"id=\"lastPricefract\">\0");
         data=strstr(all,date);
         data+=strlen(date);
         while (isdigit(*data))
            {
            suffix[counter2++]=*data;         
            *data++;
            }
         suffix[counter2]=0;
         counter2=0;
         sprintf(date,"id=\"todayVolumevalue\">\0");
         if (NULL!=(data=strstr(all,date)))
            {
            data+=strlen(date);
            while (isdigit(*data)||*data=='.')
               {
               if (isdigit(*data))
                  volume[counter2++]=*data;
               *data++;
               }
            volume[counter2]=0;
            }
         else
            strcpy(volume,"0\0");
         counter2=0;         
         sprintf(date,">Open<\0");
         data=strstr(all,date);                 
         data+=strlen(date);
         sprintf(date,">\0");
         data=strstr(data,date);                 
         data+=strlen(date);
         data=strstr(data,date);                 
         data+=strlen(date);
         if (*data=='$')
            data++;
         else if (*data=='&')
            {
            sprintf(date,";\0");
            data=strstr(data,date);                 
            data+=strlen(date);
            }
         while (isdigit(*data)||*data=='.'||*data==',')
            {
            if (isdigit(*data))
               open[counter2++]=*data;
            else if (*data==',')
               open[counter2++]='.';
            *data++;
            }
         open[counter2]=0;
         counter2=0;         
         sprintf(date,"id=\"highPricevalue\">\0");
         data=strstr(all,date);                 
         data+=strlen(date);
         while (isdigit(*data)||*data=='.'||*data==',')
            {
            if (isdigit(*data))
               high[counter2++]=*data;
            else if (*data==',')
               high[counter2++]='.';
            *data++;
            }
         high[counter2]=0;
         counter2=0;         
         sprintf(date,"id=\"lowPricevalue\">\0");
         data=strstr(all,date);                 
         data+=strlen(date);
         while (isdigit(*data)||*data=='.'||*data==',')
            {
            if (isdigit(*data))
               low[counter2++]=*data;
            else if (*data==',')
               low[counter2++]='.';
            *data++;
            }
         low[counter2]=0;
         if (strlen(prefix)&&strlen(suffix))
            {
            done++;
            fprintf(target,"%s,D,%8u,%s,%s,%s,%s.%s,%s\n",records[i].symbol,date2,open,high,low,prefix,suffix,volume);
            }
         else
            {
            counter3++;
            if (!strlen(skipped))
               strcpy(skipped,records[i].symbol);
            else
               {
               strcat(skipped," \0");
               strcat(skipped,records[i].symbol);
               }
            }
         }
      else
         {
         counter3++;
         if (!strlen(skipped))
            strcpy(skipped,records[i].symbol);
         else
            {
            strcat(skipped," \0");
            strcat(skipped,records[i].symbol);
            }
         }
      }
   DosForceDelete(records[i].symbol);
   }

fclose(target);
free(all);
free(orgdata);
free(records);
free(skipped);

printf("Import: %u\n",done);
if (strlen(skipped))
   printf("Skipped: %s (%u)\n",skipped,counter3);

return 0;
}