Annotation of sbbs/sbbs2/smm/lstphoto.c, revision 1.1.1.1

1.1       root        1: /* LSTPHOTO.C */
                      2: 
                      3: /* Developed 1990-1997 by Rob Swindell; PO Box 501, Yorba Linda, CA 92885 */
                      4: 
                      5: #include <io.h>
                      6: #include <dos.h>
                      7: #include <dir.h>
                      8: #include <bios.h>
                      9: #include <time.h>
                     10: #include <ctype.h>
                     11: #include <stdio.h>
                     12: #include <share.h>
                     13: #include <conio.h>
                     14: #include <errno.h>
                     15: #include <fcntl.h>
                     16: #include <string.h>
                     17: #include <stdlib.h>
                     18: #include <stdarg.h>
                     19: #include <malloc.h>
                     20: #include <sys/stat.h>
                     21: #include <sys/types.h>
                     22: 
                     23: #include "gen_defs.h"
                     24: #include "crc32.h"
                     25: #include "smmdefs.h"
                     26: 
                     27: extern int daylight=0;
                     28: extern long timezone=0L;
                     29: 
                     30: 
                     31: 
                     32: char *base41(unsigned int i, char *str)
                     33: {
                     34:        char c;
                     35:        unsigned int j=41*41,k;
                     36: 
                     37: for(c=0;c<3;c++) {
                     38:        k=i/j;
                     39:        str[c]='0'+k;
                     40:        i-=(k*j);
                     41:        j/=41;
                     42:        if(str[c]>=':')
                     43:                str[c]='A'+(str[c]-':');
                     44:        if(str[c]>='[')
                     45:                str[c]='#'+(str[c]-'['); }
                     46: str[c]=0;
                     47: return(str);
                     48: }
                     49: 
                     50: /****************************************************************************/
                     51: /* Updates 16-bit "rcrc" with character 'ch'                                */
                     52: /****************************************************************************/
                     53: void ucrc16(uchar ch, ushort *rcrc) {
                     54:     ushort i, cy;
                     55:     uchar nch=ch;
                     56:  
                     57: for (i=0; i<8; i++) {
                     58:     cy=*rcrc & 0x8000;
                     59:     *rcrc<<=1;
                     60:     if (nch & 0x80) *rcrc |= 1;
                     61:     nch<<=1;
                     62:     if (cy) *rcrc ^= 0x1021; }
                     63: }
                     64: 
                     65: /****************************************************************************/
                     66: /* Returns 16-crc of string (not counting terminating NULL)                 */
                     67: /****************************************************************************/
                     68: ushort crc16(char *str)
                     69: {
                     70:     int     i=0;
                     71:     ushort  crc=0;
                     72: 
                     73: ucrc16(0,&crc);
                     74: while(str[i])
                     75:     ucrc16(str[i++],&crc);
                     76: ucrc16(0,&crc);
                     77: ucrc16(0,&crc);
                     78: return(crc);
                     79: }
                     80: 
                     81: /****************************************************************************/
                     82: /* Returns 32-crc of string (not counting terminating NULL)                            */
                     83: /****************************************************************************/
                     84: ulong crc32(char *str)
                     85: {
                     86:        int i=0;
                     87:        ulong crc=0xffffffffUL;
                     88: 
                     89:        while(str[i])
                     90:                crc=ucrc32(str[i++],crc);
                     91:        crc=~crc;
                     92:        return(crc);
                     93: }
                     94: 
                     95: /****************************************************************************/
                     96: /* Converts unix time format (long - time_t) into a char str MM/DD/YY          */
                     97: /****************************************************************************/
                     98: char *unixtodstr(time_t unix, char *str)
                     99: {
                    100:        struct time curtime;
                    101:        struct date date;
                    102: 
                    103: if(!unix)
                    104:        strcpy(str,"00/00/00");
                    105: else {
                    106:        unixtodos(unix,&date,&curtime);
                    107:        if((unsigned)date.da_mon>12) {    /* DOS leap year bug */
                    108:                date.da_mon=1;
                    109:                date.da_year++; }
                    110:        if((unsigned)date.da_day>31)
                    111:                date.da_day=1;
                    112:        sprintf(str,"%02u/%02u/%02u",date.da_mon,date.da_day
                    113:                ,date.da_year>=2000 ? date.da_year-2000 : date.da_year-1900); }
                    114: return(str);
                    115: }
                    116: 
                    117: 
                    118: time_t checktime()
                    119: {
                    120:        struct tm tm;
                    121: 
                    122: memset(&tm,0,sizeof(tm));
                    123: tm.tm_year=94;
                    124: tm.tm_mday=1;
                    125: return(mktime(&tm)^0x2D24BD00L);
                    126: }
                    127: 
                    128: 
                    129: int main()
                    130: {
                    131:        char str[128],fname[128],tmp[128];
                    132:        int i,file;
                    133:        FILE *stream;
                    134:        user_t user;
                    135: 
                    136: printf("\nLSTPHOTO v1.00 - Synchronet Match Maker Photograph List\n\n");
                    137: 
                    138: if(checktime()) {
                    139:     printf("Time problem!\n");
                    140:     exit(1); }
                    141: 
                    142: if((file=open("SMM.DAB",O_RDWR|O_BINARY|SH_DENYNO|O_CREAT
                    143:     ,S_IWRITE|S_IREAD))==-1) {
                    144:        printf("\n\7Error opening/creating SMM.DAB\n");
                    145:     exit(1); }
                    146: if((stream=fdopen(file,"w+b"))==NULL) {
                    147:        printf("\n\7Error converting SMM.DAB file handle to stream\n");
                    148:     exit(1); }
                    149: setvbuf(stream,0L,_IOFBF,4096);
                    150: 
                    151: while(!feof(stream)) {
                    152:        if(!fread(&user,sizeof(user_t),1,stream))
                    153:                break;
                    154:        if(!(user.misc&USER_PHOTO) || user.misc&USER_DELETED || !user.number)
                    155:                continue;
                    156: 
                    157:        printf("%-25.25s %5lu  %-25.25s %s  ",user.system,user.number,user.name
                    158:                ,unixtodstr(user.photo,tmp));
                    159:        for(i=0;user.system[i];i++)
                    160:                if(isalnum(user.system[i]))
                    161:                        break;
                    162:        if(!user.system[i])
                    163:                fname[0]='~';
                    164:        else
                    165:                fname[0]=user.system[i];
                    166:        for(i=strlen(user.system)-1;i>0;i--)
                    167:                if(isalnum(user.system[i]))
                    168:                        break;
                    169:        if(i<=0)
                    170:                fname[1]='~';
                    171:        else
                    172:                fname[1]=user.system[i];
                    173:        fname[2]=0;
                    174:        strupr(fname);
                    175:        strupr(user.system);
                    176:        strcat(fname,base41(crc16(user.system),tmp));
                    177:        strcat(fname,base41(user.number,tmp));
                    178:        printf("%s\n",fname); }
                    179: 
                    180: return(0);
                    181: }
                    182: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.