Annotation of researchv10no/cmd/apsend/apsend.mkhd.c, revision 1.1

1.1     ! root        1: /******     apsend.mkhd.c     *****/
        !             2: 
        !             3: #include <stdio.h>
        !             4: #include <pwd.h>
        !             5: #include <time.h>
        !             6: #include <ctype.h>
        !             7: #include "apsend.h"
        !             8: 
        !             9: main()
        !            10: {
        !            11:        FILE *hdfile,*dtfile;
        !            12:        char header[160],tempbuf[80],*temp,tempbuf1[80],*temp1,tempbuf2[80],*temp2;
        !            13:        char tarray[20],parray[6],narray[8];
        !            14:        char *pid, *acct, *bin, *passacct, *nodename, *version, *aversion, *mhinfo, c;
        !            15:        char *tempbin, *tempacct;
        !            16:        int uid, i, astatus, passtype, found;
        !            17:        struct passwd *getpwuid(), *ps;
        !            18:        struct tm *localtime(), *lt;
        !            19:        long time(), now;
        !            20:        char *asctime(), *at, *getenv();
        !            21: 
        !            22:        for (i=0;i<160;i++) {
        !            23:                header[i] = ' ';
        !            24:        }
        !            25:        for (i=0;i<80;i++) {
        !            26:                tempbuf[i] = '\0';
        !            27:                tempbuf1[i] = '\0';
        !            28:                tempbuf2[i] = '\0';
        !            29:        }
        !            30:        temp = tempbuf;
        !            31:        temp1 = tempbuf1;
        !            32:        temp2 = tempbuf2;
        !            33:        found = passtype = 0;
        !            34:        astatus = 1;
        !            35:        tempbin = tempacct = 0;
        !            36: 
        !            37:        pid = getenv("PID");
        !            38:        strcpy (parray,pid);
        !            39:        nodename = getenv("NODE");
        !            40:        strcpy (narray,nodename);
        !            41:        sprintf (&header[UJN],"%s.%s",narray,parray);
        !            42:        uid = getuid();
        !            43:        ps = getpwuid(uid);
        !            44:        if (ps == NULL) {
        !            45:                printf ("login not found; job not submitted\n");
        !            46:                exit (1);
        !            47:        }
        !            48:        strcpy (&header[ULOG],ps->pw_name);
        !            49: 
        !            50:        if ((mhinfo = getenv("MHINFO")) != NULL) {
        !            51:                strcpy (temp1,mhinfo);
        !            52:                if ((tempbuf1[5] == ',') || (tempbuf1[5] == '\0'))
        !            53:                        i = 5;
        !            54:                else
        !            55:                        i = 6;
        !            56:                tempbuf1[i] = tempbuf1[i+34] = '\0';
        !            57:                tempbin = &tempbuf1[i+1];
        !            58:                strcpy (&header[BIN],tempbin);
        !            59:                tempacct = temp1;
        !            60:        }
        !            61:        if (((bin = getenv("MAILADDR")) != NULL) || (((bin = getenv("BBIN")) != NULL) && (*bin != '0'))) {
        !            62:                strcpy (temp2,bin);
        !            63:                tempbuf2[34] = '\0';
        !            64:                strcpy (&header[BIN],temp2);
        !            65:        }
        !            66:        else
        !            67:                bin = tempbin;
        !            68:        if ((acct = getenv("ACCOUNT")) != NULL){
        !            69:                strcpy (temp2,acct);
        !            70:                if ((tempbuf2[5] == ',') || (tempbuf2[5] == '\0'))
        !            71:                        i = 5;
        !            72:                else
        !            73:                        i = 6;
        !            74:                tempbuf2[i] = '\0';
        !            75:                acct = temp2;
        !            76:        }
        !            77:        else
        !            78:                acct = tempacct;
        !            79:        if (acct != NULL){
        !            80:                astatus = chkacct( acct,i);
        !            81:                if (astatus != 0){
        !            82:                        printf ("valid GCOS account number needed; job not submitted\n");
        !            83:                        exit(2);
        !            84:                }
        !            85:                strcpy (&header[MHACCT],acct);
        !            86:        }
        !            87: 
        !            88: /* try to get GCOS account and/or bin info from passwd file */
        !            89: /* determine which kind of passwd file we have: 
        !            90:        if no '(' in GCOS field, must be research type;
        !            91:                typical format is ':mhxxxx,myyy:'
        !            92:        if ')' found, followed by < 5 char string, must be ISCC standard style;
        !            93:                typical format is ':zzzzz(mhxxxx)myyy,zzzzz:' ; trailing ',zzzzz' optional;
        !            94:        if ')' found followed by 5-6 char string, must be USG style;
        !            95:                typical format is ':zzzzz(mhxxxx)mhxxxx,myyy:';
        !            96:                use account number immediately following ')';
        !            97: */
        !            98: 
        !            99:        if ((acct == NULL) || (bin == NULL)){
        !           100:                passacct = ps->pw_gecos;
        !           101:                strcpy (temp,passacct);
        !           102:                if ((acct == NULL) && (tempbuf[0] == '\0')){
        !           103:                        printf ("valid GCOS account number needed; job not submitted\n");
        !           104:                        exit(3);
        !           105:                }
        !           106:                for (i=0;i<80;i++){
        !           107:                        if (tempbuf[i] == '('){
        !           108:                                passtype=2;
        !           109:                                break;
        !           110:                        }
        !           111:                        if ((tempbuf[i] == ':' ) || (tempbuf[i] == '\0')){
        !           112:                                passtype=1;
        !           113:                                break;
        !           114:                        }
        !           115:                }
        !           116:                if (passtype == 2){
        !           117:                        for (i=0;i<80;i++){
        !           118:                                if (tempbuf[i] == ')')
        !           119:                                        found = i;
        !           120:                                if ((found != 0) && (tempbuf[i] == ','))
        !           121:                                        if (((i - found) == 6) || ((i - found) == 7))
        !           122:                                                passtype = 3;
        !           123:                                if ((tempbuf[i] == ':') || (tempbuf[i] == '\0'))
        !           124:                                        break;
        !           125:                        }
        !           126:                }
        !           127:                if (passtype == 1){
        !           128:                        passacct = temp;
        !           129:                        while ((c = *temp++) != '\0')
        !           130:                                if (c == ',') break;
        !           131:                }
        !           132:                if (passtype == 2){
        !           133:                        while (*temp++ != '(');
        !           134:                        passacct = temp;
        !           135:                        while ((c = *temp++) != '\0')
        !           136:                                if (c == ')') break;
        !           137:                }
        !           138:                if (passtype == 3){
        !           139:                        while (*temp++ != ')');
        !           140:                        passacct = temp;
        !           141:                        while ((c = *temp++) != '\0')
        !           142:                                if (c == ',') break;
        !           143:                }
        !           144:                if (bin == NULL)
        !           145:                        strcpy (&header[BIN],temp);
        !           146:                temp--;
        !           147:                *temp = '\0';
        !           148:                i = temp - passacct;
        !           149:                if (acct == NULL){
        !           150:                        astatus = chkacct( passacct,i);
        !           151:                        if (astatus != 0){
        !           152:                                printf ("valid GCOS account number needed; job not submitted\n");
        !           153:                                exit(4);
        !           154:                        }
        !           155:                        strcpy (&header[MHACCT],passacct);
        !           156:                }
        !           157:        }
        !           158:        now = time((long *)0);
        !           159:        lt = localtime(&now);
        !           160:        sprintf (&header[TODAPS],"%02d",lt->tm_mon+1);
        !           161:        sprintf (&header[TODAPS+2],"%02d",lt->tm_mday);
        !           162:        sprintf (&header[TODAPS+4],"%02d",lt->tm_hour);
        !           163:        sprintf (&header[TODAPS+6],"%02d",lt->tm_min);
        !           164:        sprintf (&header[TODAPS+8],"%02d",lt->tm_sec);
        !           165:        version = getenv("VERS");
        !           166:        strcpy (tarray,version);
        !           167:        sprintf (&header[VERSION],"%s",tarray);
        !           168:        aversion = getenv("AVERS");
        !           169:        strcpy (tarray,aversion);
        !           170:        sprintf (&header[AVERSION],"%s",tarray);
        !           171:        sprintf (&header[159],"%c",'\n');
        !           172:        for (i=0;i<160;i++)
        !           173:                if (header[i] == '\0')
        !           174:                        header[i] = ' ';
        !           175:        strcpy (tarray,"/tmp/apshead");
        !           176:        strncat (tarray,parray,5);
        !           177:        hdfile = fopen(tarray,"w");
        !           178:        strcpy (tarray,"/tmp/apsdate");
        !           179:        strncat (tarray,parray,5);
        !           180:        dtfile = fopen(tarray,"w");
        !           181:        if (hdfile == NULL || dtfile == NULL){
        !           182:                printf ("can't open /tmp file(s); job not submitted\n");
        !           183:                exit(5);
        !           184:        }
        !           185:        for (i=0;i<160;i++){
        !           186:                c = header[i];
        !           187:                putc(c,hdfile);
        !           188:        }
        !           189:        at = asctime(lt);
        !           190:        fprintf (dtfile,"%s",at);
        !           191:        exit(0);
        !           192: }
        !           193: chkacct(acct,n)
        !           194:        char acct[]; int n;
        !           195:        {
        !           196:        if ( n == 5){
        !           197:                if ((acct[0] == 'm') || (acct[0] == 'M')){
        !           198:                        acct[6] = '\0';
        !           199:                        acct[5] = acct[4];
        !           200:                        acct[4] = acct[3];
        !           201:                        acct[3] = acct[2];
        !           202:                        acct[2] = acct[1];
        !           203:                        acct[1] = 'h';
        !           204:                }
        !           205:                else
        !           206:                        return (1);
        !           207:        }
        !           208:        if ((isalpha(acct[0]) != 0) && (isalpha(acct[1]) != 0) &&
        !           209:                (isalnum (acct[2]) != 0) && (isdigit (acct[3]) != 0) &&
        !           210:                (isdigit (acct[4]) != 0) && (isdigit (acct[5]) != 0))
        !           211:                        ;
        !           212:        else
        !           213:                return (1);
        !           214:        if ((acct[2] == '0') && (acct[3] == '0') && (acct[4] == '0')
        !           215:                && (acct[5] == '0'))
        !           216:                return (2);   
        !           217:        else
        !           218:                return (0);
        !           219:        }

unix.superglobalmegacorp.com

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