/* Copyright (c) 1996 by Lele Gaifax.  All Rights Reserved
 *
 * This file is part of the PyObjC package.
 *
 * $RCSfile: StructUser.m,v $
 * $Revision: 1.1.1.2 $
 * $Date: 1996/11/14 01:49:56 $
 *
 * Created Mon Sep  9 18:24:56 1996.
 */

#include "StructUser.h"
#include <stdio.h>

#define CLASS_VERSION 0

@implementation StructUser

+ (void) initialize
{
  if (self == [StructUser class])
    {
      [StructUser setVersion:CLASS_VERSION];
    }
}

+ me
{
  struct passwd me = { "lele",
		       "whoknows",
		       100, 100, 0,
		       "no comment required",
		       "gecos field",
		       "/tmp",
		       "pysh" };
  
  return [[self alloc] initWithPasswd:me];
}

- initWithUserId:(int) uid
{
  struct passwd *entry = getpwuid (uid);

  if (entry)
    return [self initWithPasswd:*entry];
  else
    return nil;
}

- initWithPasswd:(struct passwd) aPwdEntry
{
  [super init];
  pwdEntry = aPwdEntry;
  return self;
}

- (void) show
{
  printf ("pw_name->'%s'\n", pwdEntry.pw_name);
  printf ("    pw_passwd->'%s'\n", pwdEntry.pw_passwd);
  printf ("    pw_uid->'%d'\n", pwdEntry.pw_uid);
  printf ("    pw_gid->'%d'\n", pwdEntry.pw_gid);
  printf ("    pw_quota->'%d'\n", pwdEntry.pw_quota);
  printf ("    pw_comment->'%s'\n", pwdEntry.pw_comment);
  printf ("    pw_gecos->'%s'\n", pwdEntry.pw_gecos);
  printf ("    pw_dir->'%s'\n", pwdEntry.pw_dir);
  printf ("    pw_shell->'%s'\n", pwdEntry.pw_shell);
}

- (struct passwd) pwdEntry
{
  return pwdEntry;
}

- (double) multiplyUserIdBy:(float) f
{
  return pwdEntry.pw_uid * f;
}

@end /* StructUser class implementation */
