Convert-UUlib

 view release on metacpan or  search on metacpan

uulib/uulib.c  view on Meta::CPAN


int uu_fast_scanning = 0;	/* assumes at most 1 part per file          */
int uu_bracket_policy = 0;	/* gives part numbers in [] higher priority */
int uu_verbose = 1;		/* enables/disables messages&notes          */
int uu_desperate = 0;		/* desperate mode                           */
int uu_ignreply = 0;		/* ignore replies                           */
int uu_debug = 0;		/* debugging mode (print __FILE__/__LINE__) */
int uu_errno = 0;		/* the errno that caused this UURET_IOERR   */
int uu_dumbness = 0;		/* switch off the program's intelligence    */
int uu_overwrite = 1;		/* whether it's ok to overwrite ex. files   */
int uu_ignmode = 0;		/* ignore the original file mode            */
int uu_handletext = 0;		/* do we want text/plain messages           */
int uu_usepreamble = 0;		/* do we want Mime preambles/epilogues      */
int uu_tinyb64 = 0;		/* detect short B64 outside of MIME         */
int uu_remove_input = 0;        /* remove input files after decoding        */
int uu_more_mime = 0;           /* strictly adhere to MIME headers          */
int uu_dotdot = 0;		/* dot-unescaping has not yet been done     */

headercount hlcount = {
  3,			        /* restarting after a MIME body             */
  2,                            /* after useful data in freestyle mode      */
  1                             /* after useful data and an empty line      */
};

/*
 * version string
 */

char uulibversion[256] = VERSION "pl" PATCH;

/*
 * prefix to the files on disk, usually a path name to save files to
 */

char *uusavepath;

/*
 * extension to use when encoding single-part files
 */

char *uuencodeext;

/*
 * areas to malloc
 */

char *uulib_msgstring;
char *uugen_inbuffer;
char *uugen_fnbuffer;

/*
 * The Global List of Files
 */

uulist *UUGlobalFileList = NULL;

/*
 * time values for BusyCallback. msecs is MILLIsecs here
 */

static long uu_busy_msecs = 0;	/* call callback function each msecs */
static long uu_last_secs  = 0;	/* secs  of last call to callback */
static long uu_last_usecs = 0;	/* usecs of last call to callback */

/*
 * progress information
 */

uuprogress progress;

/*
 * Linked list of files we want to delete after decoding
 */

typedef struct _itbd {
  char *fname;
  struct _itbd *NEXT;
} itbd;
static itbd * ftodel = NULL;

/*
 * for the busy poll
 */

unsigned long uuyctr;

/*
 * Areas to allocate. Instead of using static memory areas, we malloc()
 * the memory in UUInitialize() and release them in UUCleanUp to prevent
 * blowing up of the binary size
 * This is a table with the pointers to allocate and required sizes.
 * They are guaranteed to be never NULL.
 */

typedef struct {
  char **ptr;
  size_t size;
} allomap;

static allomap toallocate[] = {
  { &uugen_fnbuffer,    4096 },  /* generic filename buffer */
  { &uugen_inbuffer,    1024 },  /* generic input data buffer */
  { &uucheck_lastname,   256 },	 /* from uucheck.c */
  { &uucheck_tempname,   256 },
  { &uuestr_itemp,       256 },  /* from uuencode.c:UUEncodeStream() */
  { &uuestr_otemp,      1024 },
  { &uulib_msgstring,   1024 },  /* from uulib.c:UUMessage() */
  { &uuncdl_fulline,    1201 },  /* from uunconc.c:UUDecodeLine() */
  { &uuncdp_oline,      3600 },  /* from uunconc.c:UUDecodePart() */
  { &uunconc_UUxlat,     256 * sizeof (int) },  /* from uunconc.c:toplevel */
  { &uunconc_UUxlen,      64 * sizeof (int) },
  { &uunconc_B64xlat,    256 * sizeof (int) },
  { &uunconc_XXxlat,     256 * sizeof (int) },
  { &uunconc_BHxlat,     256 * sizeof (int) },
  { &uunconc_save,    3*1200 },  /* from uunconc.c:decoding buffer */
  { &uuscan_shlline,    1024 },  /* from uuscan.c:ScanHeaderLine() */
  { &uuscan_shlline2,   1024 },  /* from uuscan.c:ScanHeaderLine() */
  { &uuscan_pvvalue,     300 },  /* from uuscan.c:ParseValue() */
  { &uuscan_phtext,      300 },  /* from uuscan.c:ParseHeader() */
  { &uuscan_sdline,     1025 },  /* from uuscan.c:ScanData(), +1 for UURepairData */
  { &uuscan_sdbhds1,    1300 },  /* 1024 for line in UUScan + 256 potential overhead UUDecodeLine */
  { &uuscan_sdbhds2,    1300 },  /* 1024 for line in UUScan + 256 potential overhead UUDecodeLine */
  { &uuscan_spline,     1024 },  /* from uuscan.c:ScanPart() */
  { &uuutil_bhwtmp,      300 },  /* from uuutil.c:UUbhwrite() */
  { NULL, 0 }
};

/*
 * Handle the printing of messages. Works like printf.
 */

#if defined(STDC_HEADERS) || defined(HAVE_STDARG_H)
int
UUMessage (char *file, int line, int level, char *format, ...)
#else
int
UUMessage (va_alist)
  va_dcl
#endif
{
  int msgofs;
#if defined(STDC_HEADERS) || defined(HAVE_STDARG_H)
  va_list ap;

  va_start (ap, format);
#else
  char *file, *format;
  int   line, level;
  va_list ap;

  va_start (ap);
  file   = va_arg (ap, char *);
  line   = va_arg (ap, int);
  level  = va_arg (ap, int);
  format = va_arg (ap, char *);
#endif

  if (uu_debug) {
    snprintf (uulib_msgstring, 1024,  "%s(%d): %s", file, line, msgnames[level]);
    msgofs = strlen (uulib_msgstring);
  }
  else {
    snprintf (uulib_msgstring, 1024, "%s", msgnames[level]);
    msgofs = strlen (uulib_msgstring);
  }

  if (uu_MsgCallback && (level>UUMSG_NOTE || uu_verbose)) {
    vsnprintf (uulib_msgstring + msgofs, 1024 - msgofs, format, ap);

    (*uu_MsgCallback) (uu_MsgCBArg, uulib_msgstring, level);
  }

  va_end (ap);

  return UURET_OK;
}

/*
 * Call the Busy Callback from time to time. This function must be
 * polled from the Busy loops.
 */

int
UUBusyPoll (void)
{
#ifdef HAVE_GETTIMEOFDAY
  struct timeval tv;
  long msecs;

  if (uu_BusyCallback) {
    (void) gettimeofday (&tv, NULL);

    msecs = 1000*(tv.tv_sec-uu_last_secs)+(tv.tv_usec-uu_last_usecs)/1000;

    if (uu_last_secs==0 || msecs > uu_busy_msecs) {
      uu_last_secs  = tv.tv_sec;
      uu_last_usecs = tv.tv_usec;

      return (*uu_BusyCallback) (uu_BusyCBArg, &progress);
    }
  }
#else
  time_t now;
  long msecs;

  if (uu_BusyCallback) {
    if (uu_busy_msecs <= 0) {
      msecs = 1;
    }
    else {
      now   = time(NULL);
      msecs = 1000 * (now - uu_last_secs);
    }

    if (uu_last_secs==0 || msecs > uu_busy_msecs) {
      uu_last_secs  = now;
      uu_last_usecs = 0;

      return (*uu_BusyCallback) (uu_BusyCBArg, &progress);
    }
  }
#endif

  return 0;
}

/*
 * Initialization function
 */

int UUEXPORT
UUInitialize (void)
{
  allomap *aiter;

  progress.action     = 0;
  progress.curfile[0] = '\0';

  ftodel = NULL;

  uusavepath  = NULL;
  uuencodeext = NULL;

  mssdepth = 0;
  memset (&localenv, 0, sizeof (headers));
  memset (&sstate,   0, sizeof (scanstate));

  nofnum    = 0;
  mimseqno  = 0;
  lastvalid = 0;
  lastenc   = 0;
  uuyctr    = 0;

  /*
   * Allocate areas
   */

  for (aiter=toallocate; aiter->ptr; aiter++)
    *(aiter->ptr) = NULL;

  for (aiter=toallocate; aiter->ptr; aiter++) {
    if ((*(aiter->ptr) = (char *) safe_alloc (aiter->size)) == NULL) {
      /*
       * oops. we may not print a message here, because we need these
       * areas (uulib_msgstring) in UUMessage()
       */
      for (aiter=toallocate; aiter->ptr; aiter++) {
	safe_free (*(aiter->ptr), aiter->size);
      }
      return UURET_NOMEM;
    }
  }

  /*
   * Must be called after areas have been malloced

uulib/uulib.c  view on Meta::CPAN

    uu_ignmode = ivalue;
    break;
  case UUOPT_USETEXT:
    uu_handletext = ivalue;
    break;
  case UUOPT_PREAMB:
    uu_usepreamble = ivalue;
    break;
  case UUOPT_TINYB64:
    uu_tinyb64 = ivalue;
    break;
  case UUOPT_ENCEXT:
    _FP_free (uuencodeext);
    uuencodeext = _FP_strdup (cvalue);
    break;
  case UUOPT_REMOVE:
    uu_remove_input = ivalue;
    break;
  case UUOPT_MOREMIME:
    uu_more_mime = ivalue;
    break;
  case UUOPT_DOTDOT:
    uu_dotdot = ivalue;
    break;
  case UUOPT_AUTOCHECK:
    uu_autocheck = ivalue;
    break;
  default:
    return UURET_ILLVAL;
  }
  return UURET_OK;
}

char * UUEXPORT
UUstrerror (int code)
{
  return uuretcodes[code];
}

/*
 * Set the various Callback functions
 */

int UUEXPORT
UUSetMsgCallback (void *opaque, 
		  void (*func) (void *, char *, int))
{
  uu_MsgCallback = func;
  uu_MsgCBArg    = opaque;

  return UURET_OK;
}

int UUEXPORT
UUSetBusyCallback (void *opaque,
		   int (*func) (void *, uuprogress *),
		   long msecs)
{
  uu_BusyCallback = func;
  uu_BusyCBArg    = opaque;
  uu_busy_msecs   = msecs;

  return UURET_OK;
}

int UUEXPORT
UUSetFileCallback (void *opaque,
		   int (*func) (void *, char *, char *, int))
{
  uu_FileCallback = func;
  uu_FileCBArg    = opaque;

  return UURET_OK;
}

int UUEXPORT
UUSetFNameFilter (void *opaque,
		  char * (*func) (void *, char *))
{
  uu_FNameFilter = func;
  uu_FFCBArg     = opaque;

  return UURET_OK;
}

int UUEXPORT
UUSetFileNameCallback (void *opaque,
		       char * (*func) (void *, char *, char *))
{
  uu_FileNameCallback = func;
  uu_FNCBArg          = opaque;

  return UURET_OK;
}

/*
 * Return a pointer to the nth element of the GlobalFileList
 * zero-based, returns NULL if item is too large.
 */

uulist * UUEXPORT
UUGetFileListItem (int item)
{
  uulist *iter=UUGlobalFileList;

  if (item < 0)
    return NULL;
  while (item && iter) {
    iter = iter->NEXT;
    item--;
  }
  return iter;
}

/*
 * call the current filter
 */

char * UUEXPORT
UUFNameFilter (char *fname)
{



( run in 1.047 second using v1.01-cache-2.11-cpan-39bf76dae61 )