OpenBCM V1.13 (Linux)

Packet Radio Mailbox

DB0FHN

[JN59NK Nuernberg]

 Login: GUEST





  
G8PZT  > NODES    22.10.03 12:17l 122 Lines 3921 Bytes #999 (0) @ WW
BID : 090092294PZT
Read: DB0FHN GUEST DC9RD DK3HG DH8GHH
Subj: Re: Nodes list sorter - C code
Path: DB0FHN<DB0THA<DB0ERF<DB0FBB<DB0GOS<ON0AR<ON0AR<ZL2BAU<VK7AX<GB7YKS<
      GB7PZT
Sent: 031022/1005Z @:GB7PZT.#24.GBR.EU [Kidderminster] #:9209 XSERV408a
Date: Wed, 22 Oct 2003 10:05:53 +0000
From: g8pzt@gb7pzt.#24.gbr.eu (Paula)
To: nodes@ww

Subject: Re: Nodes list sorter - C code

/*******************************************************************/
/* Filename:	NSORT.C */
/* Project:	NSORT (DOS) */
/* Contents:	Turbo-c version 2.0 source code */
/* Purpose:	Nodes Table sort / extract routine */
/* Created:	22/10/03 by Paula Dowie G8PZT (g8pzt@blueyonder.co.uk) */
/* Modified:	*/
/* Notes:	This is a quick demonstration program, and is not
		guaranteed to be perfect. You should modify it as
		approriate.
		It is intended to read from a source file containing a
		normal nodes list, as produced by the "N" command on any
		node, and creates a destination file containing each node
		on a separate line, in callsign order.
		*/
/*******************************************************************/


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


#define	MAXNODES	500	/* Maximum no. of nodes we can process */

/* Structure to hold each node entry */
typedef struct node
	{
	char	callsign[11];
	char	alias[7];
	} NODE;

/* Array of structures to hold entire nodes table */
NODE NodesList[MAXNODES];


/* Function to compare callsigns of node entries */
int cmpnodes(const void *np1, const void *np2)
  {
  return (stricmp (((NODE *)np1)->callsign, ((NODE *)np2)->callsign));
  }

/* Main body of program */
void main(int argc, char *argv[])
  {
  FILE		*src, *dst;
  char		line[128], *cp, *lp;
  int		numNodes=0, i;

  /* Identify the program */
  printf ("\n\nNSORT Nodes Table Extraction/Sorter by Paula Dowie G8PZT
22/10/03\n\n");

  /* If user has given too few arguments, tell him how to use it */
  if (argc < 3)
     {
     printf ("Usage: NSORT <sourcefile> <destfile>\n\n");
     printf ("       <sourcefile> should contain unsorted nodes list\n");
     printf ("       <destfile> will receive nodes list in callsign order\n");
     exit (-1);
     }

  /* Open the source file containing the unsorted nodes list */
  if ((src = fopen (argv[1], "r")) != NULL)
     {
     /* Open the destination file to receive the sorted nodes list */
     if ((dst = fopen (argv[2], "w")) != NULL)
	{
	/* Get lines of text from the source file */
	while (fgets (line, 127, src) != NULL)
	   {
	   /* Find each colon, which separates alias:call */
	   for (lp = line; (cp = strchr (lp, ':')) != NULL; lp = cp)
	      {
	      /* Write a null in place of colon & point cp at callsign */
	      *cp++ = NULL;

	      /* Skip whitespace preceding alias:call pair */
	      while (isspace (*lp)) lp++;

	      /* Extract the callsign and alias robustly */
	      sscanf (lp, "%6s", NodesList[numNodes].alias);
	      sscanf (cp, "%10s", NodesList[numNodes].callsign);
	      numNodes++;

	      /* Skip over the alias:call to find next whitespace */
	      while (*cp && !isspace(*cp)) cp++;
	      }
	   }

	/* Sort the nodes list by callsign */
	qsort (NodesList, numNodes, sizeof (struct node), cmpnodes);

        /* Write sorted list to the destination file */
	for (i = 0; i < numNodes; i++)
	   fprintf (dst, "%-10s %s\n",
		 NodesList[i].callsign, NodesList[i].alias);

	fclose (dst);
	}
     else printf ("Error: Destination file [%s] couldn't be created\n",
argv[2]);     fclose (src);
     }
  else printf ("Error: Source file [%s] not found\n", argv[1]);

  printf ("\n%d nodes found\n", numNodes);
  }---
Packet:   G8PZT @ GB7PZT.#24.GBR.EU  (44.131.91.2) [Kidderminster]
Email:    g8pzt@blueyonder.co.uk                                   _/\_
GB7PZT:   01562-745527 24h 300-33,600 8,n,1                        (øø)
Software: XServ BBS, Xrouter, PEARL off-line-reader.                />
Web Site: www.pzt.org.uk   (also www.qsl.net/g8pzt)          ððð>ÄÄÄ>>\ÄÄÄÄ
Telnet:   (BBS): gb7pzt.dyndns.org:88  and 44.131.91.2:23
Telnet:   (KIDDER): g8pzt.ath.cx and 44.131.91.245 
HTTP:     http://g8pzt.ath.cx/ and http://44.131.91.245



Read previous mail | Read next mail


 12.01.2026 05:08:30lGo back Go up