Annotation of coherent/g/usr/lib/uucp/tay104/uupick.c, revision 1.1

1.1     ! root        1: /* uupick.c
        !             2:    Get files stored in the public directory by uucp -t.
        !             3: 
        !             4:    Copyright (C) 1992 Ian Lance Taylor
        !             5: 
        !             6:    This file is part of the Taylor UUCP package.
        !             7: 
        !             8:    This program is free software; you can redistribute it and/or
        !             9:    modify it under the terms of the GNU General Public License as
        !            10:    published by the Free Software Foundation; either version 2 of the
        !            11:    License, or (at your option) any later version.
        !            12: 
        !            13:    This program is distributed in the hope that it will be useful, but
        !            14:    WITHOUT ANY WARRANTY; without even the implied warranty of
        !            15:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
        !            16:    General Public License for more details.
        !            17: 
        !            18:    You should have received a copy of the GNU General Public License
        !            19:    along with this program; if not, write to the Free Software
        !            20:    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
        !            21: 
        !            22:    The author of the program may be contacted at [email protected] or
        !            23:    c/o Infinity Development Systems, P.O. Box 520, Waltham, MA 02254.
        !            24:    */
        !            25: 
        !            26: #include "uucp.h"
        !            27: 
        !            28: #if USE_RCS_ID
        !            29: const char uupick_rcsid[] = "$Id: uupick.c,v 1.1 93/07/30 07:59:06 bin Exp Locker: bin $";
        !            30: #endif
        !            31: 
        !            32: #include <errno.h>
        !            33: 
        !            34: #include "getopt.h"
        !            35: 
        !            36: #include "uudefs.h"
        !            37: #include "uuconf.h"
        !            38: #include "system.h"
        !            39: 
        !            40: /* Local functions.  */
        !            41: 
        !            42: static void upmovedir P((const char *zfull, const char *zrelative,
        !            43:                         pointer pinfo));
        !            44: static void upmove P((const char *zfrom, const char *zto));
        !            45: 
        !            46: /* The program name.  */
        !            47: char abProgram[] = "uupick";
        !            48: 
        !            49: /* Long getopt options.  */
        !            50: static const struct option asPlongopts[] = { { NULL, 0, NULL, 0 } };
        !            51: 
        !            52: /* Local functions.  */
        !            53: 
        !            54: static void upusage P((void));
        !            55: 
        !            56: int
        !            57: main (argc, argv)
        !            58:      int argc;
        !            59:      char **argv;
        !            60: {
        !            61:   /* -s: system name.  */
        !            62:   const char *zsystem = NULL;
        !            63:   /* -I: configuration file name.  */
        !            64:   const char *zconfig = NULL;
        !            65:   int iopt;
        !            66:   pointer puuconf;
        !            67:   int iuuconf;
        !            68:   struct uuconf_system ssys;
        !            69:   const char *zpubdir;
        !            70:   char *zfile, *zfrom, *zfull;
        !            71:   char *zallsys;
        !            72:   char ab[1000];
        !            73:   boolean fquit;
        !            74: 
        !            75:   while ((iopt = getopt_long (argc, argv, "I:s:x:", asPlongopts,
        !            76:                              (int *) NULL)) != EOF)
        !            77:     {
        !            78:       switch (iopt)
        !            79:        {
        !            80:        case 's':
        !            81:          /* System name to get files from.  */
        !            82:          zsystem = optarg;
        !            83:          break;
        !            84: 
        !            85:        case 'I':
        !            86:          /* Name configuration file.  */
        !            87:          if (fsysdep_other_config (optarg))
        !            88:            zconfig = optarg;
        !            89:          break;
        !            90: 
        !            91:        case 'x':
        !            92: #if DEBUG > 1
        !            93:          /* Set debugging level.  */
        !            94:          iDebug |= idebug_parse (optarg);
        !            95: #endif
        !            96:          break;
        !            97: 
        !            98:        case 0:
        !            99:          /* Long option found and flag set.  */
        !           100:          break;
        !           101: 
        !           102:        default:
        !           103:          upusage ();
        !           104:          break;
        !           105:        }
        !           106:     }
        !           107: 
        !           108:   if (argc != optind)
        !           109:     upusage ();
        !           110: 
        !           111:   iuuconf = uuconf_init (&puuconf, (const char *) NULL, zconfig);
        !           112:   if (iuuconf != UUCONF_SUCCESS)
        !           113:     ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
        !           114: 
        !           115:   usysdep_initialize (puuconf, INIT_GETCWD | INIT_NOCHDIR);
        !           116: 
        !           117:   zpubdir = NULL;
        !           118:   if (zsystem != NULL)
        !           119:     {
        !           120:       iuuconf = uuconf_system_info (puuconf, zsystem, &ssys);
        !           121:       if (iuuconf == UUCONF_SUCCESS)
        !           122:        {
        !           123:          zpubdir = zbufcpy (ssys.uuconf_zpubdir);
        !           124:          (void) uuconf_system_free (puuconf, &ssys);
        !           125:        }
        !           126:       else if (iuuconf != UUCONF_NOT_FOUND)
        !           127:        (void) ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
        !           128:     }
        !           129:   if (zpubdir == NULL)
        !           130:     {
        !           131:       iuuconf = uuconf_pubdir (puuconf, &zpubdir);
        !           132:       if (iuuconf != UUCONF_SUCCESS)
        !           133:        ulog_uuconf (LOG_FATAL, puuconf, iuuconf);
        !           134:     }
        !           135: 
        !           136:   if (! fsysdep_uupick_init (zsystem, zpubdir))
        !           137:     usysdep_exit (FALSE);
        !           138: 
        !           139:   zallsys = NULL;
        !           140:   fquit = FALSE;
        !           141: 
        !           142:   while (! fquit
        !           143:         && ((zfile = zsysdep_uupick (zsystem, zpubdir, &zfrom, &zfull))
        !           144:             != NULL))
        !           145:     {
        !           146:       boolean fdir;
        !           147:       char *zto, *zlocal;
        !           148:       FILE *e;
        !           149:       boolean fcontinue;
        !           150: 
        !           151:       fdir = fsysdep_directory (zfull);
        !           152: 
        !           153:       do
        !           154:        {
        !           155:          fcontinue = FALSE;
        !           156: 
        !           157:          if (zallsys == NULL
        !           158:              || strcmp (zallsys, zfrom) != 0)
        !           159:            {
        !           160:              if (zallsys != NULL)
        !           161:                {
        !           162:                  ubuffree (zallsys);
        !           163:                  zallsys = NULL;
        !           164:                }
        !           165: 
        !           166:              printf ("from %s: %s %s ?\n", zfrom, fdir ? "dir" : "file",
        !           167:                      zfile);
        !           168: 
        !           169:              if (fgets (ab, sizeof ab, stdin) == NULL)
        !           170:                break;
        !           171:            }
        !           172: 
        !           173:          if (ab[0] == 'q')
        !           174:            {
        !           175:              fquit = TRUE;
        !           176:              break;
        !           177:            }
        !           178: 
        !           179:          switch (ab[0])
        !           180:            {
        !           181:            case '\n':
        !           182:              break;
        !           183: 
        !           184:            case 'd':
        !           185:              if (fdir)
        !           186:                (void) fsysdep_rmdir (zfull);
        !           187:              else
        !           188:                {
        !           189:                  if (remove (zfull) != 0)
        !           190:                    ulog (LOG_ERROR, "remove (%s): %s", zfull,
        !           191:                          strerror(errno));
        !           192:                }
        !           193:              break;
        !           194: 
        !           195:            case 'm':
        !           196:            case 'a':
        !           197:              zto = ab + 1 + strspn (ab + 1, " \t");
        !           198:              zto[strcspn (zto, " \t\n")] = '\0';
        !           199:              zlocal = zsysdep_uupick_local_file (zto);
        !           200:              if (zlocal == NULL)
        !           201:                usysdep_exit (FALSE);
        !           202:              zto = zsysdep_in_dir (zlocal, zfile);
        !           203:              ubuffree (zlocal);
        !           204:              if (zto == NULL)
        !           205:                usysdep_exit (FALSE);
        !           206:              if (! fdir)
        !           207:                upmove (zfull, zto);
        !           208:              else
        !           209:                {
        !           210:                  usysdep_walk_tree (zfull, upmovedir, (pointer) zto);
        !           211:                  (void) fsysdep_rmdir (zfull);
        !           212:                }
        !           213:              ubuffree (zto);
        !           214: 
        !           215:              if (ab[0] == 'a')
        !           216:                {
        !           217:                  zallsys = zbufcpy (zfrom);
        !           218:                  ab[0] = 'm';
        !           219:                }
        !           220: 
        !           221:              break;
        !           222: 
        !           223:            case 'p':
        !           224:              if (fdir)
        !           225:                ulog (LOG_ERROR, "Can't print directory");
        !           226:              else
        !           227:                {
        !           228:                  e = fopen (zfull, "r");
        !           229:                  if (e == NULL)
        !           230:                    ulog (LOG_ERROR, "fopen (%s): %s", zfull,
        !           231:                          strerror (errno));
        !           232:                  else
        !           233:                    {
        !           234:                      while (fgets (ab, sizeof ab, e) != NULL)
        !           235:                        (void) fputs (ab, stdout);
        !           236:                      (void) fclose (e);
        !           237:                    }
        !           238:                }
        !           239:              fcontinue = TRUE;
        !           240:              break;
        !           241: 
        !           242:            case '!':
        !           243:              (void) system (ab + 1);
        !           244:              fcontinue = TRUE;
        !           245:              break;
        !           246: 
        !           247:            default:
        !           248:              printf ("uupick commands:\n");
        !           249:              printf ("q: quit\n");
        !           250:              printf ("<return>: skip file\n");
        !           251:              printf ("m [dir]: move file to directory\n");
        !           252:              printf ("a [dir]: move all files from this system to directory\n");
        !           253:              printf ("p: list file to stdout\n");
        !           254:              printf ("! command: shell escape\n");
        !           255:              fcontinue = TRUE;
        !           256:              break;
        !           257:            }
        !           258:        }
        !           259:       while (fcontinue);
        !           260: 
        !           261:       ubuffree (zfull);
        !           262:       ubuffree (zfrom);
        !           263:       ubuffree (zfile);
        !           264:     }
        !           265: 
        !           266:   (void) fsysdep_uupick_free (zsystem, zpubdir);
        !           267: 
        !           268:   usysdep_exit (TRUE);
        !           269: 
        !           270:   /* Avoid error about not returning.  */
        !           271:   return 0;
        !           272: }
        !           273: 
        !           274: /* Print usage message.  */
        !           275: 
        !           276: static void
        !           277: upusage ()
        !           278: {
        !           279:   fprintf (stderr,
        !           280:           "Taylor UUCP version %s, copyright (C) 1991, 1992 Ian Lance Taylor\n",
        !           281:           VERSION);
        !           282:   fprintf (stderr,
        !           283:           "Usage: uupick [-s system] [-I config] [-x debug]\n");
        !           284:   fprintf (stderr,
        !           285:           " -s system: Only consider files from named system\n");
        !           286:   fprintf (stderr,
        !           287:           " -x debug: Set debugging level\n");
        !           288: #if HAVE_TAYLOR_CONFIG
        !           289:   fprintf (stderr,
        !           290:           " -I file: Set configuration file to use\n");
        !           291: #endif /* HAVE_TAYLOR_CONFIG */
        !           292:   exit (EXIT_FAILURE);
        !           293: }
        !           294: 
        !           295: /* This routine is called by usysdep_walk_tree when moving the
        !           296:    contents of an entire directory.  */
        !           297: 
        !           298: static void
        !           299: upmovedir (zfull, zrelative, pinfo)
        !           300:      const char *zfull;
        !           301:      const char *zrelative;
        !           302:      pointer pinfo;
        !           303: {
        !           304:   const char *ztodir = (const char *) pinfo;
        !           305:   char *zto;
        !           306: 
        !           307:   zto = zsysdep_in_dir (ztodir, zrelative);
        !           308:   if (zto == NULL)
        !           309:     usysdep_exit (FALSE);
        !           310:   upmove (zfull, zto);
        !           311:   ubuffree (zto);
        !           312: }
        !           313: 
        !           314: /* Move a file.  */
        !           315: 
        !           316: static void
        !           317: upmove (zfrom, zto)
        !           318:      const char *zfrom;
        !           319:      const char *zto;
        !           320: {
        !           321:   (void) fsysdep_move_file (zfrom, zto, TRUE, TRUE, FALSE,
        !           322:                            (const char *) NULL);
        !           323: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.