gnu_stuff.c 4.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
/*
 * gnu_stuff.c
 */

/* lsftp, an implementation of the sftp protocol
 *
 * Copyright (C) 2001 Pontus Sköld
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#if HAVE_CONFIG_H
# include "config.h"
#endif

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include "gnu_stuff.h"

void lsftp_welcome()
{
  printf( "Welcome to %s by Pontus Sköld, Niels Möller and various.\n", PACKAGE_STRING );
  printf( "This program is free software, for more information\n" );
  printf( "please see the file COPYING or type about, you may\n" );
  printf( "also use help or ? to get help.\n\n");
  printf( "Trying to connect, please stand by.\n");

}

void help_option()
{
  printf( "Usage: lsftp [ <transport options> ] \n" );
  printf( "or:    lsftp [ <transport options> ] -- [ COMMAND ] [ COMMAND ] \n" );
  
  printf( "For information on the commands of lsftp, you may try the built in help\n" );
  printf( "by running lsftp -- help (please note the space between -- and help).\n" );
  printf( "\n");
  printf( "INTERACTIVE MODE:\n" );
  printf( "\n");
  printf( "To enter interactive mode, just start lsftp. A command prompt will appear.\n");
  printf( "To try the built in help system, type help (or ?) followed by return.\n");
  printf( "\n");
  printf( "NON-INTERACTIVE MODE:\n" );
  printf( "\n");
  printf( "Non interactive mode can be accessed by having -- anywhere in front of\n" );
  printf( "the last token of the commandline (you need to have something after it)\n");

  printf( "\n");
  printf( "In order NOT to pass into non interactive mode (e.g. if you want to pass -- \n");
  printf( "to your secsh-client), put -- with nothing following last on the command line.\n");
  printf( "\n");
  printf( "For noninteractive usage, each token is handled as a complete line, so to \n");
  printf( "go to the directory bar and put the file foo, you'd write something like\n");
  printf( "\n");
  printf( "lsftp host -- 'cd bar' 'put foo' \n");
  printf( "\n");
  printf( "TROUBLESHOOTING CONNECTIONS:\n" );
  printf( "\n");
  printf( "All lsftp really cares about is to find something to speak sftp with,\n");
  printf( "normally, it does with by requesting a subsystem on a remote host, but it\n");
  printf( "may as well start a local program or request the start of a sftp-server\n");
  printf( "remotely with a shell request\n");
  printf( "\n");
  printf( "The command actually executed is\n" );
  printf( "\n");
  printf( "$LSFTP_RSH $LSFTP_BEFORE_ARGS <anything on the command line> $LSFTP_AFTER_ARGS\n");
  printf( "\n");
  printf( "Report bugs to <bug-lsh@gnu.org>.\n" );
  printf( "\n");

  exit(0); /* Exit successfully */
}

void version_option()
{
  printf("%s\n", PACKAGE_STRING);
  printf("Copyright (C) Pontus Sköld, Niels Möller and various contributors\n\n");

  printf("This program is free software, you may distribute it under the\n");
  printf("terms of the GNU Genereal Public License. \n\n");
  
  printf("This program is distributed in the hope that it will be useful,\n");
  printf("but WITHOUT ANY WARRANTY; without even the implied warranty of\n");
  printf("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU\n");
  printf("General Public License for more details.\n");

  exit(0); /* Exit successfully */
}

void do_gnu_stuff( const char** argv )
{
  const char** current = argv;

  while( *current ) /* More arguments? */
    {
      if( !strcmp( *current, "--version" ) )
	version_option();

      if( !strcmp( *current, "--help" ) )
	help_option();

      current++;
    }
}


#ifndef HAVE_CANONICALIZE_FILE_NAME

/* Compability function, taken from a parted patch */

char*
canonicalize_file_name (const char* name)
{
  char* buf;
  int size;
  char* result;
  
#ifdef PATH_MAX
  size = PATH_MAX;
#else
  /* Bigger is better; realpath has no way todo bounds checking.  */
  size = 4096;
#endif

  /* Just in case realpath does not NULL terminate the string
   * or it just fits in SIZE without a NULL terminator.  */
  buf = calloc( size + 1, 1 );
 
  if( !buf ) 
    {
      errno = ENOMEM;
      return NULL;
    }

  result = realpath(name, buf);

  if (! result)
    free (buf);

  return result;
}
#endif /* !HAVE_CANONICALIZE_FILE_NAME */