The macosxhints Forums

The macosxhints Forums (http://hintsforums.macworld.com/index.php)
-   UNIX - Newcomers (http://hintsforums.macworld.com/forumdisplay.php?f=15)
-   -   Newbie with some questions (http://hintsforums.macworld.com/showthread.php?t=11390)

eldwin 04-29-2003 06:29 PM

Newbie with some questions
 
Hello all,

I'm new to the mac / unix world. I recently just purchased a powerbook 12 inch and installed the developer tools.

I have a few questions:

When i am in the unix terminal, I've logged into unix as the root user and i get the message: tcsh: cannot open /etc/termcap
tcsh: using dumb terminal settings.

also, i'm using gcc and i can compile and make just fine, but when i'm running my program i get a: terminal database is inaccessible.

The code works because i've tested it in linux. What i'm doing is writing and reading from files (.txt and .dat.) One of the kids in school said in might be a permissions problem.

I would apreciate any and all advice on this matter.

Eldwin

hayne 04-30-2003 02:02 AM

details needed
 
How about some more details of what you are doing?
Are you by any chance using a xterm under X Windows? (If so, this query is more suited for the X Windows section of the forums.)
Does your program make use of a curses-based user interface?
If you are 'root', then it is very unlikely that you are having permission problems.
The more basic problem is that something in the software you are using (your own program or the terminal it is running in) is looking for the file /etc/termcap. This file does not exist on a standard OS X system.

eldwin 04-30-2003 04:12 AM

I'm not sure what you mean by xterm and X window.

I'm in a software engineering class and we've put together a text based role playing game.

During execution of the program, you are required to create or choose a previously created player. (Both will require to read info from a .txt file and .dat file.) The program does write to file properly, but it bails out when trying to read from file.

Like i said, it works on Linux as far as reading, writing, playing the game.

I'm just unfamiliar with these error messages.

Thanks for your help

Eldwin

sao 04-30-2003 08:22 AM

Quote:

eldwin wrote:
When i am in the unix terminal, I've logged into unix as the root
Can you give us more info on how you do it?

hayne 04-30-2003 08:57 AM

Terminal
 
Quote:

Originally posted by eldwin
I'm not sure what you mean by xterm and X window.
So then, can I assume that you are using the "Terminal" application that is suppled by Apple under the Application/Utilities folder?

Quote:

I'm in a software engineering class and we've put together a text based role playing game.
Tell us what the interaction with the game is like. Did you write this part of the game or were you supplied with some of the software?

Quote:

Like i said, it works on Linux as far as reading, writing, playing the game.
Unfortunately, the code working on Linux merely means that it should be relatively easy to port to OS X - there is no guarantee of it automatically working without you making changes to the code to make it OS X compatible.

That is why I asked above about the user-interface of the game. A program with straight text-input from a prompt and straight text-output will work without changes on any UNIX system. But if you do anything fancy in the user-interface, like positioning text at a certain place on the screen (as opposed to just letting it scroll up in the Terminal) then you have to be careful to avoid system dependencies. It sounds like some part of your program has such system dependencies, otherwise it wouldn't be looking for the file /etc/termcap. This may be a library that you are linking against - not necessarily just the code that you wrote.

Here's a test program, just to check that your basic input & output is working.
Try compiling and running this program and let us know what happens with it.
(Not sure if you are using C or C++, so I stuck to plain C.)
Code:

#include <stdio.h>
#include <stdlib.h>
int main(void)
{
    printf("Hello Eldwin\n");
    printf("Enter an integer:\n");
    int num;
    if (scanf("%d", &num) != 1)
    {
        fprintf(stderr, "Bad input\n");
        exit(1);
    }
    FILE *fp = fopen("junk.txt", "w");
    if (fp == 0)
    {
        fprintf(stderr, "Can't open file for writing\n");
        exit(1);
    }
    fprintf(fp, "%d\n", num);
    fclose(fp);
    printf("Your number was written to the file \"junk.txt\"\n");
    return 0;
}


eldwin 05-03-2003 03:59 AM

I've narrowed down the problem to reading and writing from/to binary .dat files.
In an attempt to prevent hacking of the game, we stored all the info of players/monsters/equipment in binary.dat files.

Obviously when someone opens one of these files up in a notepad, its going to look like a bunch of garbage.


As far as input, its just taking straight text input and displaying straight text output.

hayne 05-03-2003 04:09 AM

answers?
 
You still haven't answered some of the questions I asked.
- are you using the Terminal program from Utilities?
- are you linking with any libraries?

What exactly are the problems you are having with these binary files? What does the reading & writing of binary files have to do with termcap - or are we now talking about a different problem?

eldwin 05-03-2003 02:40 PM

Ok when I start Darwin (yes it is a terminal from utilities), I type in 'login' and enter my user name and password.

After I do so, I get the file/etc/termcap line.

The folder, where the source files are located, are on the desktop.

I can compile the program using the makefile.

The program does start up and runs until it is required to read from the .dat file.

BTW, What is termcap?

Again i appreciate your help on this matter.

Eldwin

djhyp3rion 05-03-2003 03:24 PM

Maybe there's a command in your ~/.tcsh that's trying to access the /etc/termcap. Just a suggestion...

hayne 05-03-2003 07:04 PM

Quote:

Ok when I start Darwin (yes it is a terminal from utilities), I type in 'login' and enter my user name and password
Whoah - slow down a minute. Let's start from the point where you are logged on your Mac. I'm assuming you are typing on the keyboard of the Mac - not doing a remote login to a Mac from some other machine. Ok then you double-click on Terminal in the Utilities folder and a new Terminal window opens. You don't need to enter your username & password in this window since you are already logged into the Mac. Does this correspond with what you are doing? You make it sound different when you talk about typing your name & password after mentioning Terminal.
(added afterwards:) Oh - now I see that you said that you type in the command 'login'. Don't do that - you are already logged in. (I tried typing 'login' as you do and I see that same error about termcap - strange - I'll investigate why this happens but anyway, just avoid the 'login' and all should be well.)

Quote:

After I do so, I get the file/etc/termcap line.
If you are saying that you get an error message about termcap after starting a new Terminal window, this definitely means that djhyp3rion is right - you have something in your "dot" files (e.g. ~/.cshrc, ~/.tcshrc, ~/.login, etc) that is causing this. It would be something that you added yourself as there is nothing like that there normally. So edit those files and remove anything suspicious by putting a comment character (#) at the start of the lines.

Quote:

The program does start up and runs until it is required to read from the .dat file.
And then what happens?

Quote:

BTW, What is termcap?
Your answer is here: http://www.google.com/search?q=termcap

mervTormel 05-03-2003 07:44 PM

FWIW, this condition can be invoked thusly:
Code:

# normal login

% echo $TERM
vt100

% setenv TERM network
tcsh: Cannot open /etc/termcap.
tcsh: using dumb terminal settings.

# bork'd


hayne 05-03-2003 09:10 PM

TERM=network
 
Right. So it seems (I looked at the source for tcsh) that this is partly a case of a bad error message. The code is using the function 'tgetent' which queries the terminfo database (which is what replaces /etc/termcap on OS X - and many other UNIX variants).
Since for some reason the environment variable TERM is set to "network" when the /usr/bin/login program is run, it is looking for a terminfo entry for "network" and such doesn't exist. The tcsh code then complains about /etc/termcap not existing - which is a bogus error message.

All the above was perhaps not of interest to anyone but myself - but the bottom line regarding the original poster's problem remains the same:
Don't use the 'login' command when you are already logged in.

mervTormel 05-03-2003 09:32 PM

thank you, sir.

WillyT 05-06-2003 10:03 PM

Not just login?
 
Unless su calls login.:D

Code:

[dreamersound:~] williamt% su root
Password:
_su: Cannot open /etc/termcap.
_su: using dumb terminal settings.

Well I always wondered about that and now I know. Thanks guys.

hayne 05-06-2003 10:20 PM

su
 
I don't see that problem when I su to another user:

su fred

I don't have root enabled, so can't try that but maybe you can try su-ing to some other user than root to see if this is only a difficulty with root.

WillyT 05-06-2003 10:58 PM

Every user it seems.
 
Code:

[dreamersound:~] williamt% su tester
Password:
_su: Permission denied
_su: Trying to start from "/Users/tester"
_su: Cannot open /etc/termcap.
_su: using dumb terminal settings.
[dreamersound:~] tester% exit
exit
[dreamersound:~] williamt% su geraldin
Password:
_su: Permission denied
_su: Trying to start from "/Users/geraldin"
_su: Cannot open /etc/termcap.
_su: using dumb terminal settings.
[dreamersound:~] geraldin%

I understand the "Permission denied" as all users home dirs are 700 so the pwd can't see my home and it has to change.

hayne 05-06-2003 11:11 PM

what about 'su -' ?
 
What happens if you use 'su -' instead of 'su' ?
E.g.:
su - fred
This effectively does a login as that user.
You might be seeing this "termcap" problem with su due to your 700 permissions.

WillyT 05-07-2003 09:35 AM

Need .termcap
 
Here's the problem:
Code:

[dreamersound:~] williamt% setenv
HOME=/Users/williamt
SHELL=/bin/tcsh
USER=williamt
LANG=en_US
PATH=/sw/share/Geomview/bin:/sw/bin:/sw/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin:/usr/local/X11/bin
__CF_USER_TEXT_ENCODING=0x1F5:0:0
TERM=vt100-color
TERMCAP=���
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=81
...

The 3 ? all have a Diamond around them(char value 65533)(double byte chars?).

Yes and su - works for the Permission denied message.

So I put my .termcap and my .terminfo dir into the other users home dir and I can su - cleanly.

The TERM=vt100-color thing is part of the color ls mod. Which now works for each user. (dang its hard to remember all the little hacks we do)

I found this when I logged in as tester and started Terminal.app and up pops the "Cannot open /etc/termcap" message. I think I remember fighting this back when I first installed Jaguar too.

Thanks


All times are GMT -5. The time now is 05:57 PM.

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.