TIP: Click on subject to list as thread! ANSI
echo: fidosoft.husky
to: All
from: Markus Reschke
date: 2013-12-12 14:06:56
subject: htick: rename option

Hello!

- fileearea "-rename" switch to rename files in case of duplicate names
  in the fileecho
  "-noRename" to disable renaming (default)
- new incoming file is renamed to
  file..more.ext for long filenames
  file.<1st char of extnumber> for DOS style filenames
   is  01 - 99
- examples:
  file.zip -> file.z01
  long-name.tar.gz -> long-name.01.tar.gz
- linked nodes will get files with the original name in any case


In file fidoconf/fidoconf/fidoconf.h in "typedef struct area" insert after
   int nodiz;          /*  1 - do not try to get description from
 */
>  int rename;         /*  1 - rename file in case of duplicates */

In file fidoconf/src/line.c in function parseAreaOption() insert
>    else if (strcmp(iOption, "rename")==0) {
>        if( area->areaType == FILEAREA ) {
>            area->rename = 1;
>        }else{
>            prErr("Option '%s' is allowed for fileareas
only!",iOption);
>            nfree(iOption);
>            return 1;     /*  error */
>        }
>    }
>    else if (strcmp(iOption, "norename")==0) {
>        if( area->areaType == FILEAREA ) {
>            area->rename = 0;
>        }else{
>            prErr("Option '%s' is allowed for fileareas
only!",iOption);
>            nfree(iOption);
>            return 1;     /*  error */
>        }
>    }
before:
     else if (strcmp(iOption, "diz")==0) {

In file fidoconf/src/tparser.c in function printFileArea() insert after
  if(area.replace)
    printf("replace ");
  else
    printf("noReplace ");
following:
> if(area.norename)
>   printf("noRename ");
> else
>   printf("rename ");


Run "make clean", "make", "make install" and
recompile & update any husky programm linked to libfidoconf including
libareafix.


In file htick/h/global.h in "struct ticfiletype" insert after
  char *file;         /*  Name of the file affected by Tic */
following:
> char *altfile;      /*  alternative filename for duplicates */

In file htick/src/toss.c in function disposeTic() insert after
   nfree(tic->file);
following:
>  nfree(tic->altfile);

In file htick/src/toss.c add following new function before sendToLinks():

/*
 *  create alternative filename for ticed file
 *  - add counter 01 up to 99
 *
 *  requires:
 *  - path of destination directory
 *  - name of ticed file
 *
 *  returns:
 *  - string pointer (allocated buffer) on success
 *  - NULL on any problem
 */

char *altFilename(char *path, char *name)
{
  char              *altName = NULL;         /* return value */
  char              *tempName = NULL;        /* temporary name */
  char              *tempFilepath = NULL;    /* temporary filepath */
  char              *modStr;
  char              *remStr = NULL;
  unsigned int      n = 1;
  size_t            size;

  /* sanity checks */
  if ((path == NULL) || (name == NULL)) return altName;

  /* allocate buffers */
  size = strlen(name) + 4;         /* + dot + 2 digits + \0 */
  tempName = smalloc(size);
  size += strlen(path);
  tempFilepath = smalloc(size);

  /* prepare temp. name */
  strcpy(tempName, name);
  modStr = strchr(tempName, '.');         /* find first dot */
  if (modStr == NULL)              /* no dot found */
  {
    /* find end of string */
    modStr = tempName;
    while (modStr[0] != 0) modStr++;

    modStr[0] = '.';               /* add dot */
  }
  else                             /* dot found */
  {
    /* get pointer to remaining part in original string */
    remStr = strchr(name, '.');
  }
  modStr++;                        /* skip dot */
  modStr[0] = 0;                   /* end string */

  if (isDOSLikeName(name))         /* DOS filename */
  {
    if (remStr)                    /* more chars follow */
    {
      remStr++;                    /* skip dot */
      modStr[0] = remStr[0];       /* copy first char behind dot */
      modStr++;                    /* and skip it */
      remStr = NULL;               /* don't care about the remaining chars */
    }
  }

  /* check alternative names */
  while (n < 99)
  {
    /* complete temp. filename */
    sprintf(modStr, "%.2d", n);              /* add counter */
    if (remStr) strcat(modStr, remStr);      /* add remaining part */

    strcpy(tempFilepath, path);              /* build full filepath */
    strcat(tempFilepath, tempName);    

    if (!fexist(tempFilepath)) break;        /* unused filename */
    else n++;                                /* try next one */
  }

  if (n <= 99) altName = tempName;           /* found alternative */
  else nfree(tempName);                      /* found none */
  nfree(tempFilepath);

  return altName;
}


In file htick/src/toss.c in function sendToLinks() replace
<   if(filearea->msgbType != MSGTYPE_PASSTHROUGH &&
filearea->noreplace && fexist(newticedfile)) {
<       w_log(LL_ERROR,"File %s already exist in filearea %s. Can't
replace it",tic->file,tic->area);
<       return(3);
<   }
with:
>   /* check for duplicate in filearea */
>   if (filearea->msgbType != MSGTYPE_PASSTHROUGH &&
fexist(newticedfile))
>   {
>     if (filearea->rename)             /* rename new file */
>     {
>       comm = altFilename(&fileareapath[0], tic->file);
>       if (comm != NULL)     /* found alternative name */
>       {
>         strcpy(newticedfile, fileareapath);
>         strcat(newticedfile, comm);
>         tic->altfile = comm;
>         w_log('6',"Created alternative name %s for file %s.", comm, 
> tic->file);
>       }
>       else                  /* namespace exceeded or error */
>       {
>         w_log(LL_ERROR,"Couldn't create alternative name for file %s in 
> filearea %s.", tic->file, tic->area);
>         return(3);
>       }
>     }
>     else if (filearea->noreplace)     /* don't overwrite old file */
>     {
>       w_log(LL_ERROR,"File %s already exist in filearea %s. Can't replace 
> it",tic->file,tic->area);
>       return(3);
>     }
>   }

And just below that change
<   if (!filearea->sendorig) {
into:
>   if (!filearea->sendorig && tic->altfile == NULL) {

About 40 lines below that replace
<   if (filearea->sendorig) {
with:
>   if (filearea->sendorig || tic->altfile) {

Another 20 lines below change
<   if (filearea->msgbType != MSGTYPE_PASSTHROUGH) {
<       strcpy(descr_file_name, filearea->fileName);
<       strcat(descr_file_name, config->fileDescription);
<       adaptcase(descr_file_name);
<       removeDesc(descr_file_name,tic->file);
<       if (tic->anzldesc>0)
<           add_description (descr_file_name, tic->file,
tic->ldesc, tic->anzldesc);
<       else
<           add_description (descr_file_name, tic->file,
tic->desc, tic->anzdesc);
<   }
into:
>   if (filearea->msgbType != MSGTYPE_PASSTHROUGH) {
>       strcpy(descr_file_name, filearea->fileName);
>       strcat(descr_file_name, config->fileDescription);
>       adaptcase(descr_file_name);
>       if (tic->altfile) comm = tic->altfile;    /* use alternative name */
>       else comm = tic->file;                    /* use original name */
>       removeDesc(descr_file_name, comm);
>       if (tic->anzldesc>0)
>           add_description (descr_file_name, comm, tic->ldesc, 
> tic->anzldesc);
>       else
>           add_description (descr_file_name, comm, tic->desc,
tic->anzdesc);
>   }


Run "make clean", "make", "make install" and enjoy ;-)

Regards,
Markus

--- 
* Origin: *** theca tabellaria *** (2:240/1661)
SEEN-BY: 3/0 633/267 640/954 712/0 550 848
@PATH: 240/1661 1120 2432/200 280/5003 464 712/848 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.