Category : Communication (modem) tools and utilities
Archive   : TXT2FON1.ZIP
Filename : TXT2FON.C

 
Output of file : TXT2FON.C contained in archive : TXT2FON1.ZIP
/*
// // Copyright (C) 1994
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/



#include
#include
#include
#include

#define FON_REC_LEN 118
#define DOS_FILE_NAME_LEN 13
#define IN_LEN 133
#define NAME_LEN 27
#define NAME_OFFSET 1
#define PH_LEN 19
#define PH_OFFSET 31


void usage(char *name)
{

printf("\treads BBS names and phone numbers from text listings");
printf(" and inserts them\n\tinto a QModem .fon list beginning at a ");
printf(" specified record number. \n\tText records must have one ");
printf(" name/number per line, lines are \n\tdelimited. An old .fon file");
printf(" and a new .fon file must be specified.\n\tNOTE:: No checking is");
printf(" done on the data from either input file - it's\n\tvery possible");
printf(" to create junk from junk. Also, if a file already exists\n\tthen");
printf(" it will NOT be overwritten.");
printf("\n\nusage:\t%s <.txt> ", name);
printf(" \n\n\twhere\t\tis");
printf("\n\t\tnumber where new records start");
printf("\n\t<.txt>\t\trelative path name of text file");
printf("\n\t\tname of old .fon file");
printf("\n\t\tname of new .fon file");
printf("\n\t\t\tBeginning character position of BBS name");
printf("\n\t\t\tLength of BBS name");
printf("\n\t, \tSame for BBS phone number");
printf("\n\n");
exit(0);
}


void main(int argc, char *argv[])
{
int rec_num, max_lines = 200, p1, p2, l1, l2, i, j, k1, k2, tmp_int;
char line_fon[119], in_line[IN_LEN], tmp_char;
char file_names[3][DOS_FILE_NAME_LEN],
*index, check = '\\';
FILE *files[3];

index = strrchr( argv[0], check);
if( index == NULL ) index = argv[0];
else index++;


printf("\ntxt2fon! By Brian Allison\nCopyright under GNU General Public");
printf("License version 2\n");

if( argc != 9 )
usage(index);

rec_num = atoi(argv[1]);
if( (rec_num < 1) || (rec_num > max_lines) )
{ printf("\n\nThe first available record is 1 and the last is %d.", max_lines);
printf("\nFor instructions, enter \"%s\"", index);
exit(0);
}

for( i = 0; i < 3; i++ )
if( strlen( argv[i+2]) <= DOS_FILE_NAME_LEN)
strcpy( file_names[i], argv[i+2] );
else
{ printf("\n\n%s is too long to be a DOS filename!\n", argv[i+2]);
printf("\nFor instructions, enter \"%s\"", index);
exit(0);
}

p1 = atoi(argv[5]);
if( (l1 = atoi(argv[6])) <= 0)
{ printf("\n\nThe name may not be empty!");
printf("\nFor instructions, enter \"%s\"", index);
exit(0);
}
p2 = atoi(argv[7]);
if( (p2 == p1) || ((p2 > p1) && (p1 + l1 > p2)) )
{ printf("\n\nThe number may not overlap with the name!");
printf("\nFor instructions, enter \"%s\"", index);
exit(0);
}
l2 = atoi(argv[8]);
if( (l2 <= 0) || ( (p2 < p1) && (p2 + l2 > p1)) )
{ printf("\n\nThe number may not overlap with the name!");
printf("\nFor instructions, enter \"%s\"", index);
exit(0);
}

if( (files[0] = fopen(file_names[0], "r")) == NULL )
{ printf("\nCould not open file %s! Aborting...", file_names[0]);
exit(0);
}
if( (files[1] = fopen(file_names[1], "rb")) == NULL )
{ printf("\nCould not open file %s! Aborting...", file_names[1]);
exit(0);
}

if( (files[2] = fopen(file_names[2], "rb")) != NULL )
{
printf("\nOutput file %s already exists!", file_names[2]);
for( i = 0; i < 3; i++ ) fclose(files[i]);
exit(0);
}
else
if( (files[2] = fopen(file_names[2], "w+b")) == NULL )
{
printf("\nCannot open output file %s!", file_names[2]);
for( i = 0; i < 2; i++ ) fclose(files[i]);
exit(0);
}

for( i = 1; i < rec_num; i++ )
{ // Here we just read a record from old.fon and write it to new.fon
for( j = 0; j < FON_REC_LEN; j++ )
line_fon[j] = fgetc(files[1]);
line_fon[85] = 'Z';
line_fon[112] = (char)0xc2;
line_fon[113] = (char)0x01;
for( j = 0; j < FON_REC_LEN; j++ )
fputc(line_fon[j], files[2]);
}


k1 = (NAME_LEN < l1? NAME_LEN : l1);
k2 = (PH_LEN < l2 ? PH_LEN : l2);
for( ; (i <= max_lines) && !feof(files[0]); i++ )
{ // Here we read in the text file AND the old.fon, overwriting parts
// of the new.fon.

// Read in an entire line from the old.fon file
for( j = 0; j < FON_REC_LEN; j++ )
line_fon[j] = fgetc(files[1]);

// Read in an entire line from the text file
fgets( in_line, IN_LEN, files[0]);
// Make sure that any characters are lower case unless following a
// space.
for( j = 1; j < strlen(in_line); j++ )
if( (in_line[j-1] != ' ') && isupper(in_line[j]) )
in_line[j] = tolower(in_line[j]);

// Copy the BBS name from the text line to the fon line
// instead of running j in {0..k} and writing to line_fon[(j+1)],
// I chose to put k one more. Now I can run j in {1..k} and
// write to line_fon[j], which is quicker.
// Position 0 of each record holds the text length of the name
line_fon[0] = (char)k1;
for( j = 0; j < k1; j++ )
line_fon[j+NAME_OFFSET] = in_line[p1+j-1];

// Same thing, number.
// Position 30 of each record holds the text length of the number
line_fon[30] = (char)k2;
for( j = 0; j <= k2; j++ )
line_fon[j+PH_OFFSET] = in_line[p2+j-1];

// Emtpy the 'last date called' field
line_fon[70] = line_fon[71] = (char)0;

// Set the 'number times called' field to 0
line_fon[79] = line_fon[80] = line_fon[81] = (char)0;

// Set the default Protocol to Z (ZModem)
line_fon[85] = 'Z';

// Flag the damn board for dialing! 🙂
line_fon[104] = (char)1;

// Set the default speed to 115200 baud (autodetect)
line_fon[112] = (char)0xc2;
line_fon[113] = (char)0x01;

// Now that line_fon is changed, write it out to the new.fon file
for( j = 0; j < FON_REC_LEN; j++ )
fputc(line_fon[j], files[2]);
}

// Here we just read a record from old.fon and write it to new.fon
for( ; i <= max_lines; i++ )
{ // Here we just read a record from old.fon and write it to new.fon
for( j = 0; j < FON_REC_LEN; j++ )
line_fon[j] = fgetc(files[1]);
line_fon[85] = 'Z';
line_fon[112] = (char)0xc2;
line_fon[113] = (char)0x01;
for( j = 0; j < FON_REC_LEN; j++ )
fputc(line_fon[j], files[2]);
}


for( i = 0; i < 3; i++ ) fclose(files[i]);
printf("\n");
}

  3 Responses to “Category : Communication (modem) tools and utilities
Archive   : TXT2FON1.ZIP
Filename : TXT2FON.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/