Category : C Source Code
Archive   : MF2PCPAK.ZIP
Filename : UNCRUNCH.C

 
Output of file : UNCRUNCH.C contained in archive : MF2PCPAK.ZIP
#include
#include
#include
#include
#include
#include
#include

#define MAX_STR 13000
#define MAX_LINE 135
#define DLE ((char) '~')
#define SCHAR ((int) 32)



char line_txt[MAX_LINE+5], data_str[MAX_STR+5];

int f1;
FILE *f2;

/**/
main(argc, argv)
int argc;
char **argv;
{
int flag, data_sub, line_sub, char_line, repeat_number, rec_on, rec_saved, rec_len;
char c, cc, prev_char, rec_num[10];


if (argc != 3)
{
printf("\nUsage: UNCRUNCH \n\n");
exit(1);
}


if ((f1 = open(argv[2], O_WRONLY | O_CREAT | O_TRUNC, S_IREAD | S_IWRITE)) == NULL)
{
printf("\nCan't create - %s\n", argv[2]);
goto errexit;
}

if ((f2 = fopen(argv[1], "r")) == NULL)
{
printf("\nCan't open - %s\n", argv[1]);
goto errexit;
}


if (fgets(line_txt, MAX_LINE, f2) == NULL)
{
printf("\nCan't READ header record - %s\n", argv[1]);
goto errexit1;
}
/*
strncpy(rec_num, &line_txt[0], 2);
rec_num[2] = '\0';
rec_len = atoi(rec_num);
if (rec_len != 0)
{
printf("\nError Header record not found - %s\n", line_txt);
goto errexit1;
}
*/
strncpy(rec_num, line_txt, 5);
rec_num[5] = '\0';
rec_len = atoi(rec_num);

char_line = atoi(&line_txt[5]) + 1;


prev_char = c = '\0';
data_sub = 0;

data_str[0] = '\0';

rec_on = rec_saved = 0;
printf("\nRECORDS READ -%5d RECORDS SAVED -%5d ", rec_on, rec_saved);

while (1) /* do forever */
{
if (fgets(line_txt, MAX_LINE, f2) == NULL)
break;

printf("\rRECORDS READ -%5d", ++rec_on);


if (c != DLE)
{
line_sub = 1;
c = line_txt[0];
}
else
line_sub = 0;


for ( ; line_sub < char_line && c != '\0' ; line_sub++)
{
if (c == DLE)
{
if ((line_sub + 1) >= char_line)
break;

repeat_number = (int) line_txt[line_sub];

repeat_number -= SCHAR;

if (repeat_number > 0)
{
line_sub++; /* skip the repeat count */
repeat_number += 2; /* already storaged the previous character once */

while (repeat_number--)
data_str[data_sub++] = prev_char;

c = line_txt[line_sub];

continue;
}
}

data_str[data_sub++] = c;
prev_char = c;

c = line_txt[line_sub];
}

data_str[data_sub] = '\0';

while (data_sub >= rec_len)
{
cc = data_str[rec_len];

data_str[rec_len] = '\n';

flag = write(f1, data_str, (rec_len + 1));

if (flag == -1 || flag < (rec_len + 1))
{
printf("\n *** ERROR - on write(at eof) to disk *** \n\n");
goto errexit1;
}

printf("\rRECORDS READ -%5d RECORDS SAVED -%5d ", rec_on, ++rec_saved);

data_str[rec_len] = cc;

strcpy(data_str, &data_str[rec_len]);

data_sub = strlen(data_str);
};
};


rec_on++;


while (data_sub >= rec_len)
{
cc = data_str[rec_len];

data_str[rec_len] = '\n';

flag = write(f1, data_str, (rec_len + 1));

if (flag == -1 || flag < (rec_len + 1))
{
printf("\n *** ERROR - on write(at eof) to disk *** \n\n");
goto errexit1;
}

printf("\rRECORDS READ -%5d RECORDS SAVED -%5d ", rec_on, ++rec_saved);

data_str[rec_len] = cc;

strcpy(data_str, &data_str[rec_len]);

data_sub = strlen(data_str);
};


if (data_sub > 0)
{
data_str[data_sub] = '\n';

flag = write(f1, data_str, (data_sub + 1));

if (flag == -1 || flag < (data_sub + 1))
{
printf("\n *** ERROR - on write(at eof) to disk *** \n\n");
goto errexit1;
}

printf("\rRECORDS READ -%5d RECORDS SAVED -%5d ", rec_on, ++rec_saved);

if (data_sub != rec_len)
printf("\n\n ** Last Record is TOO %s (%d chars/%d chars in record) **\n",
(data_sub < rec_len ? "SHORT" : "LONG"), data_sub, rec_len);

}


printf("\n\nNormal COMPELETION\n\n");

errexit1:
close(f1);
fclose(f2);

exit(-1);

errexit:
printf("\n\n*** ERROR EXIT ***\n\n");
exit(-1);
}


  3 Responses to “Category : C Source Code
Archive   : MF2PCPAK.ZIP
Filename : UNCRUNCH.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/