Author Topic: Compiling Tolower tool  (Read 5892 times)

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4710
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Compiling Tolower tool
« on: February 03, 2021, 01:00:07 am »
Hi

I want to compile a very simple command line tool called "tolower", that converts the files of a directory to lowercase.

1) I can compile it with it's makefile (nmake) with icc.exe (3.6), but it links the file to the "CPPRSI36.DLL" runtime.
I'm not sure if there is a DLL that came bundled with ArcaOS that can be used to replace the "CPPRSI36.DLL" runtime... like "OS2OM30.DLL"? or it is a completely different thing?


2) I also tried to compile it with gcc just to try it out. I get this error.
Quote
[E:\projects\tolower1]gcc -I. -Zomf -o tolower.exe tolower.c
tolower.c:13:12: fatal error: os2.h: No such file or directory
   13 |   #include <os2.h>
      |            ^~~~~~~
compilation terminated.
Where I'm missing to include "C:\usr\include\os2tk45" on the config.sys so gcc can find os2.h ?

Regards
« Last Edit: February 03, 2021, 01:09:54 am by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4710
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling Tolower tool
« Reply #1 on: February 03, 2021, 01:28:11 am »
1) I can compile it with it's makefile (nmake) with icc.exe (3.6), but it links the file to the "CPPRSI36.DLL" runtime.
I'm not sure if there is a DLL that came bundled with ArcaOS that can be used to replace the "CPPRSI36.DLL" runtime... like "OS2OM30.DLL"? or it is a completely different thing?

Hi
I did some guessing, I replaced the "ctype.h" from "D:\IBMCXXO\include" to the one included on the OS2TK45 (D:\OS2TK45\h\libc) and I recompiled.

Now "tolower.exe" did not have dependency on "CPPRSI36.DLL" and seems to be working. I'm not sure if I did the right thing.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: Compiling Tolower tool
« Reply #2 on: February 03, 2021, 03:47:31 am »
Hi Martin.
I don't know icc much but I'd assume one of the compiler options decides which ctypes.h to use and moving around include files is generally discouraged. I'd read the documentation to see what the options do and it'll likely be obvious which needs changing. One example from EMX was whether to use the single threaded or multi-threaded library. Needed the single threaded library for DOS.
GCC uses its own os2.h in @unixroot/usr/include, which depending on a define (look at os2.h) can use the toolkit or os2emx.h. Usually using the default os2emx.h is fine.
I just compiled it with
Code: [Select]
gcc -Zomf tolower.c
and stupidly converted all the files in my download directory to lowercase :)
Neither GCC or ICC should need the -I. (include current directory) and with the -Zomf, the linker (wl.exe) will produce an executable if you don't tell it otherwise. Hmm, seems that without the -Zomf, ld also now produces an executable too, though much bigger. Used to produce a.out which then needed to be bound to be an executable.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: Compiling Tolower tool
« Reply #3 on: February 03, 2021, 04:01:42 am »
If you want to program, copy tolower.c to to toupper.c and replace tolower with toupper in line 29, change the printf and now you have a program to uppercase file names.
Getting more fancy, you could test the file name and do either depending on name or add a parameter.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4710
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling Tolower tool
« Reply #4 on: February 03, 2021, 02:31:19 pm »
Thanks Dave for the tip. I will also create "toupper" as you suggest for the fun of it.

Dave, by any chance do you know of a good open source example (for OS/2) of a command line tool that can be good to analyze as a "source code skeleton of a command line tool", that may have, multiple input parameters (/s /? etc) and several language support?.

I'm just curious is some sample can be produced as a "source code skeleton of a command line tool" in C.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4710
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling Tolower tool
« Reply #5 on: February 03, 2021, 02:37:24 pm »
Hi

I produced the 1.1 release. It is not much but I least I can say now that I have compiled something for OS/2 :)
https://github.com/OS2World/UTIL-DISK-ToLower|

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4710
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling Tolower tool
« Reply #6 on: February 03, 2021, 02:42:29 pm »
Hi

Even that it compiles with icc, I still want to try to compile it with gcc.

I still get this error:
Quote
[E:\projects\tolower1]gcc -Zomf tolower.c
tolower.c:13:12: fatal error: os2.h: No such file or directory
   13 |   #include <os2.h>
      |            ^~~~~~~
compilation terminated.

I think I may have something wrong on the config.sys.  Or may it be better to have a separate SETENV.CMD file?

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: Compiling Tolower tool
« Reply #7 on: February 03, 2021, 04:19:21 pm »
Try
Code: [Select]
gcc -Ic:/usr/include -Zomf tolower.c

GCC should be hard coded to search @unixroot/usr/include. Also of course make sure that c:\usr\include\os2.h exists.
I'll think on a skeleton, might be something in the examples of icc or OW.

Andi B.

  • Hero Member
  • *****
  • Posts: 811
  • Karma: +11/-2
    • View Profile
Re: Compiling Tolower tool
« Reply #8 on: February 03, 2021, 06:35:09 pm »
I've 'SET C_INCLUDE_PATH=P:\usr\include;....' in my config.sys for gcc

Ian Manners

  • Global Moderator
  • Sr. Member
  • *****
  • Posts: 463
  • Karma: +10/-0
  • I am the computer, it is me.
    • View Profile
    • ComKal Networks Australia
Re: Compiling Tolower tool
« Reply #9 on: February 04, 2021, 04:08:37 pm »
This is the os2.h I use with watcom C

Code: [Select]
/*static char *SCCSID = "@(#)os2.h      6.6 92/03/15";*/
/****************************** Module Header ******************************\
*                                                                          *
* Copyright (c) 1987  - 1992 IBM Corporation                               *
*                                                                          *
* Module Name: OS2.H                                                       *
*                                                                          *
* This is the top level include file that includes all the files necessary *
* for writing an OS/2 application.                                         *
*                                                                          *
\***************************************************************************/

#ifndef __OS2_H__

/* NOINC */
#if __IBMC__ || __IBMCPP__
   #pragma info( none )
      #ifndef __CHKHDR__
         #pragma info( none )
      #endif
   #pragma info( restore )
#endif
#ifdef __cplusplus
      extern "C" {
#endif

#define __OS2_H__
/* INC */

#define OS2_INCLUDED

/* Common definitions */
#include <os2def.h>

/* OS/2 Base Include File */
#ifndef INCL_NOBASEAPI
   #include <bse.h>
#endif /* INCL_NOBASEAPI */

/* OS/2 Presentation Manager Include File */
#ifndef INCL_NOPMAPI
   #include <pm.h>
#endif /* INCL_NOPMAPI */

/* NOINC */
/* Open Scripting Architecture (OSA) Include File */
#ifdef INCL_OSAAPI
   #include <osa.h>
#endif /* INCL_OSAAPI */

#ifdef __cplusplus
        }
#endif
#if __IBMC__ || __IBMCPP__
   #pragma info( none )
      #ifndef __CHKHDR__
         #pragma info( restore )
      #endif
   #pragma info( restore )
#endif

/* OpenDoc for OS/2 Include File */
#ifdef __cplusplus
#ifdef INCL_ODAPI
   #include <od.h>
#endif /* INCL_ODAPI */
#endif
/* INC */

#endif /* __OS2__ */

As an example.
Cheers
Ian B Manners

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4710
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling Tolower tool
« Reply #10 on: February 04, 2021, 05:52:34 pm »
Hi

Sorry if it is a dumb question, but I'm not experienced on this subject.

As a good practice, all development should use the same os2.h (as some other headers) or it is mandatory that each development tool had their own version of os2.h ?

I know that in practice each dev tool package their own different version like 4.5 Toolkit RPM, 4.5 toolkit installer on eComStation (CD) ,  VAC 3.6 and Watcom.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: Compiling Tolower tool
« Reply #11 on: February 04, 2021, 07:20:05 pm »
Generally, all the os2.h headers should be equivalent. In practice the toolkit os2.h is the most up to date and preferred, though in a lot of cases the other os2.h work just as well.
Different compilers are different, and while icc and OW can directly use the toolkit and it is preferred, GCC's os2.h starts out by including os2safe.h which is needed for redefining various 16 bit functions that will crash if using high memory, -Zhigh-mem. If you look at the GCC version, it can be edited to use the toolkit os2.h after setting a few things up, mostly calling conventions or a program can use a define to use the toolkit.
So in the case of GCC, you should use the os2.h in usr\include which can include the toolkit one, which it also has to find, so you need to use the right -I or %C_INCLUDE_PATH% to find it.
Remember too that up till eCS (or the convenience packs?), the toolkit was not freely available so you had to use the ones that came with the compiler.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4786
  • Karma: +99/-1
    • View Profile
Re: Compiling Tolower tool
« Reply #12 on: February 04, 2021, 07:25:24 pm »
Hi Martin.
I don't know icc much but I'd assume one of the compiler options decides which ctypes.h to use and moving around include files is generally discouraged. I'd read the documentation to see what the options do and it'll likely be obvious which needs changing.

Someone informed me that it wasn't the compiler options that decided on which ctypes.h you used and that the options were mostly fine though it was suggested to get rid of the ""cOOl" /G5" switch (Pentium code). Also that plain "icc tolower.c" should work to compile.
I'd guess that your include directive in your setenv or config.sys needs to point to the toolkit first to not use the weird ctypes.h.

edit, looking at your config.sys that you posted, the set include line looks correct, not sure about the set LIB line though. At one point I had this for icc,
Code: [Select]
SET LIB=k:\usr\lib;F:\UTILS\UODBC\LIB;%TK%\SOM\LIB;%TK%\LIB;%TK%\SAMPLES\MM\LIB;%TK%\SPEECH\LIB;G:\IBMCPP\LIB;G:\IBMCPP\DLL;with TK set to the location of the toolkit.
« Last Edit: February 04, 2021, 07:32:55 pm by Dave Yeo »