🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: demon.ip.developers
Article #1311

Re: ADDGROUP with 'real' names

#1311
From: John Washington
Date: Thu, 30 Nov 1995 00:00
185 lines
6348 bytes
On Wednesday, in article <817661125snz@keris.demon.co.uk>
     chris@keris.demon.co.uk "Chris Croughton" wrote:

CC> Some time ago someone (John Washington?) said that they had a version of
CC> the SNEWS ADDGROUP program that generated names which bore some
CC> resemblance to the newsgroup, rather than the usual time-based ones.

In case anyone else wants, I'll post it here, also just in case I've
forgotten to mail it to Malcolm.

If you dig around in newsgroup files at all, I simply can't
imagine being without this mod.

When is the next Snews release, Malcolm?  I've been holding back
on doing further mods until 1.31, in particular because I hope
you'll do more restructuring to reduce the large chunks of repeated
code.

Changes are to addgroup.c, addition of new files nicename.c/.h,
and the obvious changes to makefile (exercise for rdr).  Sorry I
can't give diffs, or line numbers, I've made too many other changes;
I'll quote a little context instead.

I've expanded tabs to 4 spaces.  (Tabs?  Just say 'no').

-------------------------------------
Mods to addgroup.c:
#include "locking.h"

#ifdef JW_NICE_FILENAMES
#include "nicename.h"
#endif

-------------------------------------
    #ifndef JW_NICE_FILENAMES
    time_t          t;
    #endif
-------------------------------------
                added = added2 = FALSE;
                if (active_file != NULL) {

                    #ifdef JW_COMMENT
                    //> Strange logic, has to be true, see above.
                    #endif

                    #ifndef JW_NICE_FILENAMES
                    /* delay ensures names are different - ahem */
#ifdef __OS2__
                    os2_delay(1000);
#else
#ifdef __TURBOC__
                    delay(1000);
#else
                    goal = 1000 + clock();
                    while (goal > clock());
#endif
#endif
                    sprintf(txt_name, "%ld", time(&t));
                    if (strlen(txt_name) > 8) {
                        strcpy(txt_name, txt_name + (strlen(txt_name) - 8));
                    }
                    #else
                    {
                        // Create a 'sensible' name
                        nice_new_newsgroup_name (argv[i], txt_name, sizeof txt_name);
                        printf ("\n%s %s\n", argv [i], txt_name);   // Print the filename chosen, just for interest.
                    }
                    #endif  // else def JW_NICE_FILENAMES
-------------------------------------
                        fprintf(stderr, "addgroup: newsbase name collision - try again\n");
                        fclose(new_active_file);

                        #ifdef JW_NICE_FILENAMES
                        // *** BUG *** BUG *** BUG ***
                        // I don't think this should be here even for the old code.  
                        // I certainly don't want it with my new code.
                        #else
                        unlink(buf);
                        #endif

                        exit(1);
-------------------------------------
New file nicename.c:
// nicename.c

// Nice filenames in ~\spool\news\newsbase.
// This module is only used by addgroup.exe (and mail2snz.exe).

#include "defs.h"

#ifdef JW_NICE_FILENAMES

#include <ctype.h>  // for isdigit
#include <io.h>
#include <stdio.h>
#include <string.h>

#include "nicename.h"


void nice_new_newsgroup_name (const char* ngn, char* txt_name, int txt_name_len)
{
    const char* lastbit = ngn + 1;
    int j;
    
    if (txt_name_len < 9)
    {
        txt_name [0] = '\0';
        return;
    }

    txt_name [0] = ngn [0];
    for (j = 1; j < 7; j++)     // j points at next unset ch in txt_name.
    {
        // Find the next '.'
        for (;; ngn++)
        {
            if (*ngn == '.')
            {
                ++ngn;
                break;
            }
            if (*ngn == '\0')
                break;
        }
        if (*ngn == '\0' 
            || *ngn == '.')     // (firewall in case ".." in n/grp)
        {
            break;
        }
        txt_name [j] = *ngn;
        lastbit = ngn + 1;
    }
    if (j > 1)
    {           // Make the name prettier, by adding underscore
        txt_name [j] = txt_name [j-1];
        txt_name [j-1] = '_';
        ++j;
    }
    if (j < 8)
        strncpy (txt_name + j, lastbit, 8 - j);
    txt_name [8] = '\0';

    // txt_name[] now holds a name up to 8 chars, a candidate
    // for the new file to hold this newsgroup.  Collisions
    // are possible, so allow the final character to be replaced
    // with a digit.  In practice this should give sufficient
    // variety, but something smarter could replace more than
    // the last char.

    j = '0';    // Prepare to try replacing final ch with digit
    for (;;)
    {
        char buf [256];
        sprintf(buf, "%snewsbase\\%s", my_stuff.news_dir, txt_name);
        if (access(buf, 0) != 0)
            break;      // Success, found a name that doesn't exist.
        if (!isdigit (j) 
            || txt_name [0] == '\0')  // (imposs, but test anyway)
            break;      // Failure, let the caller sort it out.
        txt_name [strlen (txt_name) - 1] = j;
        j++;
    }
} // nice_new_newsgroup_name

#endif  // def JW_NICE_FILENAMES

// EOF
-------------------------------------
New file nicename.h:
// nicename.h

// Nice filenames in ~\spool\news\newsbase.
// This module is only used by addgroup.exe.

#ifdef JW_NICE_FILENAMES

void nice_new_newsgroup_name (const char* ngn, char* txt_name, int txt_name_len);

#else
    #error nicename.h shouldn't be included.
#endif

// EOF
-------------------------------------  end of mods & additions
Technical Details
Message-ID: <817745608snz@wash.demon.co.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <817661125snz@keris.demon.co.uk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10bb05,32d7a9ff38d6545d
X-Google-Attributes: gid10bb05,public
From: John Washington <john@wash.demon.co.uk>
Subject: Re: ADDGROUP with 'real' names
Date: 1995/11/30
Message-ID: <817745608snz@wash.demon.co.uk>
X-Deja-AN: 120612271
x-nntp-posting-host: wash.demon.co.uk
x-disclaimer: I am not aware of infringing software patents in this
references: <817661125snz@keris.demon.co.uk>
newsgroups: demon.ip.developers
x-gnu-license: Yes!