Annotation of researchv10dc/cmd/docgen/otrans.l, revision 1.1.1.1

1.1       root        1: %{
                      2: #include <sys/types.h>
                      3: #include <pwd.h>
                      4: #include <sys/stat.h>
                      5: #include <time.h>
                      6: #include "header.h"
                      7: 
                      8: char *wpn = "311403-0101";     /*default 1127 workproject number*/
                      9: #define DATE DOCNUM+6
                     10: #define SEQNUM DOCNUM+13
                     11: #define TYPE DOCNUM+15
                     12: #define SOFT DOCNUM+17
                     13: struct passwd *getpwuid(), *ps;
                     14: int soft;
                     15: char *p, *s1, *s2;
                     16: char *getarg();
                     17: int type, ci=0, pm=0, rl=0;
                     18: char buf[HEADSIZE];
                     19: char *co = &buf[CO];
                     20: char *dept = &buf[DOCNUM], *date = &buf[DATE], *seqnum = &buf[SEQNUM];
                     21: char *stype = &buf[TYPE], *ssoft = &buf[SOFT];
                     22: char *machine = buf;
                     23: char *login = &buf[ULOG], *timestamp = &buf[TIMESTAMP];
                     24: char *version = &buf[VERSION];
                     25: char *pages = &buf[PAGES];
                     26: int more = 1;
                     27: %}
                     28: %%
                     29: ^".so".*       ;
                     30: ^".TI" {
                     31:        printf(".TL\n");
                     32:        }
                     33: ^".DT".*       ;
                     34: ^".AH".*       {
                     35:        s1 = s2 = &yytext[0];
                     36:        p = getarg();
                     37:        yytext[yyleng] = '\0';
                     38:        printf(".AU %s \"\" %s\n",p, s2+2);
                     39:        more = 1;
                     40:        }
                     41: ^".AP".*       {
                     42:        yytext[yyleng] = '\0';
                     43:        printf(".rP %s\n",&yytext[3]);
                     44:        }
                     45: ^".SA" {
                     46:        printf(".AS\n");
                     47:        }
                     48: ^".SE" {
                     49:        printf(".AE\n");
                     50:        }
                     51: ^".KW".*       {
                     52:        printf(".OK %s\n",&yytext[3]);
                     53:        }
                     54: ^".TY".*       {
                     55:        for(p = &yytext[3]; *p == ' ';p++);
                     56:        if(*p == 'I')type=2;
                     57:        else if(*(p+1) == 'M')type=1;
                     58:        else type=3;
                     59:        *stype = *p;
                     60:        *(stype+1) = *(p+1);
                     61:        while(*p != ' '){
                     62:                if(*p == '\n'){
                     63:                        soft=0;
                     64:                        break;
                     65:                }
                     66:                p++;
                     67:        }
                     68:        if(*p == ' ')
                     69:                if(*++p == 'y')
                     70:                        soft=1;
                     71:        printf(".MT %d\n",type);
                     72:        if(soft){
                     73:                *ssoft = 'S';
                     74:                printf(".sF\n");
                     75:        }
                     76:        }
                     77: ^".NU".*       {
                     78:        yytext[yyleng] = '\0';
                     79:        type = 0;
                     80:        s1 = s2 = &yytext[0];
                     81:        p = getarg();
                     82:        if(p != 0){
                     83:                sprintf(dept,"%s-",p);
                     84:                printf(".dN %s-",p);
                     85:                type = 1;
                     86:        }
                     87:        if(more){
                     88:                p = getarg();
                     89:                if(p != 0){
                     90:                        sprintf(date,"%s-",p);
                     91:                        printf("%s-",p);
                     92:                }
                     93:        }
                     94:        if(more){
                     95:                p = getarg();
                     96:                if(p != 0){
                     97:                        *seqnum = *p;
                     98:                        *(seqnum+1) = *(p+1);
                     99:                        printf("%s\n",p);
                    100:                }
                    101:                else if(type) printf("\n");
                    102:        }
                    103:        if(more){
                    104:                p = getarg();
                    105:                if(p != 0)
                    106:                        printf(".fC %s\n",p);
                    107:                if(more){
                    108:                        p = getarg();
                    109:                        if(p != 0)
                    110:                                printf(".wP %s\n",p);
                    111:                        else printf(".wP %s\n",wpn);
                    112:                }
                    113:        }
                    114:        more = 1;
                    115:        }
                    116: ^".MY".*       {
                    117:        printf(".mE %s\n",&yytext[3]);
                    118:        }
                    119: ^".ED".*       {
                    120:        printf(".eD %s'n",&yytext[3]);
                    121:        }
                    122: ^".PR".*       {
                    123:        pm=1;
                    124:        printf(".PM %s\n",&yytext[3]);
                    125:        }
                    126: ^".RL".*       {
                    127:        rl=1;
                    128:        if(yyleng>3){
                    129:                p=&yytext[3];
                    130:                while(*p == ' ')p++;
                    131:                if(*p == '\"')p++;
                    132:                if(*p == 'n')printf(".fA n\n");
                    133:                else printf(".fA y\n");
                    134:        }
                    135:        else printf(".fA y\n");
                    136:        }
                    137: ^".GS" {
                    138:        printf(".gS\n");
                    139:        }
                    140: ^".CI".*       {
                    141: /*     ci = 1;         gone away
                    142:        if(yyleng == 3)
                    143:                printf(".cI n\n");
                    144:        else {
                    145:                p = &yytext[3];
                    146:                while(*p == ' ')p++;
                    147:                if(*p == '\n' || *p == 'n')
                    148:                        printf(".cI n\n");
                    149:                else if(*p == '\"')p++;
                    150:                if(*p == 'y')
                    151:                        printf(".cI y\n");
                    152:                else if(*p == '\"' || *p == 'n')
                    153:                        printf(".cI n\n");
                    154:                else    fprintf(stderr,".CI unknown argument %c\n",*p);
                    155:        }*/
                    156:        }
                    157: ^".CO".*       {
                    158: /*     if(!ci){
                    159:                printf(".cI n\n");
                    160:                ci = 1;
                    161:        }*/
                    162:        if(!rl){
                    163:                printf(".fA y\n");
                    164:                rl = 1;
                    165:        }
                    166:        printf(".cC\n");
                    167:        }
                    168: ^".CE" {
                    169:        printf(".cE\n");
                    170:        }
                    171: ^".CV".*       {
                    172: /*     if(!ci){
                    173:                printf(".cI n\n");
                    174:                ci = 1;
                    175:        }*/
                    176:        if(!rl){
                    177:                printf(".fA y\n");
                    178:                rl = 1;
                    179:        }
                    180:        printf(".cS\n");
                    181:        }
                    182: ^".SC".*       {
                    183: /*     if(!ci){
                    184:                printf(".cI n\n");
                    185:                ci = 1;
                    186:        }*/
                    187:        if(!rl){
                    188:                printf(".fA y\n");
                    189:                rl = 1;
                    190:        }
                    191:        p = s1 = &yytext[3];
                    192:        while(*s1 == ' ')s1++;
                    193:        while(*s1 != ' ')s1++;
                    194:        while(*s1 == ' ')s1++;
                    195:        while(*s1 != ' ')s1++;
                    196:        *s1 = '\0';
                    197:        s1++;
                    198:        printf(".CS %s \"\" %s\n", p, s1);
                    199:        return(0);
                    200:        }
                    201: .*     {
                    202:        ECHO;
                    203:        printf("\n");
                    204:        }
                    205: \n     ;
                    206: %%
                    207: char *header="/tmp/            ";
                    208: char *dest = "mhuxd!/usr/spool/uucppublic/doc.mcs";
                    209: char *dco = "BL";
                    210: main(argc, argv)
                    211: char *argv[];
                    212: {
                    213:        FILE *inp;
                    214:        char *filename, *name, *cover, *pid;
                    215:        int nuchars, npid, uid, days;
                    216:        long mtime;
                    217:        if(argc < 3){
                    218:                fprintf(stderr,"file name must be supplied to sendcover\n");
                    219:                exit(1);
                    220:        }
                    221:        if((inp=fopen("/etc/whoami","r")) == NULL){
                    222:                fprintf(stderr,"can't open /etc/whoami\n");
                    223:                exit(1);
                    224:        }
                    225:        nuchars = fread(machine, sizeof(char), 10, inp);
                    226:        nuchars -= 1;
                    227:        if(nuchars < 5)pid = machine + nuchars +1;
                    228:        else pid = machine + 6;
                    229:        cover = pid + 5;
                    230:        fclose(inp);
                    231:        *(pid-1) = '.';
                    232:        npid = getpid();
                    233:        sprintf(pid,"%05d",npid);
                    234:        *cover = 'c';
                    235:        sprintf(&header[5],"%s",machine);
                    236:        uid = getuid();
                    237:        if ((ps = getpwuid(uid)) == NULL){
                    238:                fprintf(stderr, "login not found");
                    239:                exit(1);
                    240:        }
                    241:        strcpy (login,ps->pw_name);
                    242:        sprintf(version,"080687L");     /*version*/
                    243:        strcpy(co, dco);        /*company name=BL*/
                    244:        name = argv[1];
                    245:        argc--; argv++;
                    246:        if(freopen(argv[1],"r",stdin)==NULL) {
                    247:                fprintf(stderr,"%s: cannot open\n", argv[1]);
                    248:                exit(1);
                    249:        }
                    250:        if(freopen(header,"w",stdout)== NULL){
                    251:                fprintf(stderr,"%s: cannot open\n",header);
                    252:                exit(1);
                    253:        }
                    254:        if((nuchars = fwrite(buf,sizeof(char),HEADSIZE,stdout)) != HEADSIZE){
                    255:                fprintf(stderr,"wrong number of characters written %d\n",nuchars);
                    256:                        exit(1);
                    257:        }
                    258:        filename = argv[1];
                    259:        mtime = getstamp(filename);
                    260:        sprintf(timestamp,"%ld",mtime);
                    261:        argv++;
                    262:        sprintf(pages,"TP%s",argv[1]);
                    263:        yylex();
                    264:        rewind(stdout);
                    265:        for(p=buf; p < &buf[HEADSIZE-1]; p++)
                    266:                if(*p == '\0')*p = ' ';
                    267:        *p = '\n';
                    268:        if((nuchars = fwrite(buf,sizeof(char),HEADSIZE,stdout)) != HEADSIZE){
                    269:                fprintf(stderr,"wrong number of characters written %d\n",nuchars);
                    270:                        exit(1);
                    271:        }
                    272:        *(cover+1) = '\0';
                    273:        if((inp=fopen(name,"a")) == NULL){
                    274:                fprintf(stderr,"can't open tmp file %s\n",name);
                    275:                exit(1);
                    276:        }
                    277:        fprintf(inp,"cd /tmp; uucp -m -C %s %s; rm %s\n",machine,dest,machine);
                    278:        fclose(inp);
                    279: }      
                    280: char *
                    281: getarg()
                    282: {
                    283:        if(s1 == s2){
                    284:                while(*s1 != ' ')
                    285:                        if(*s1++ == '\0'){
                    286:                                more = 0;
                    287:                                return(0);
                    288:                        }
                    289:        }
                    290:        else s1 = s2+1;
                    291:        if(*s1 == ' ')
                    292:                while(*s1 == ' ')s1++;
                    293:        if(*s1 == '\0'){
                    294:                more = 0;
                    295:                return(0);
                    296:        }
                    297:        if(*s1 == '\"'){
                    298:                if(*(s1+1) == '\"'){
                    299:                        s2 = s1+1;
                    300:                        return(0);
                    301:                }
                    302:                for(s2=s1+1; *s2 != '\"'; s2++);
                    303:                if(*(s2+1) == '\0'){
                    304:                        more = 0;
                    305:                        *(s2+1) = '\0';
                    306:                        return(s1);
                    307:                }
                    308:                else {
                    309:                        *(s2+1) = '\0';
                    310:                        return(s1);
                    311:                }
                    312:        }
                    313:        for(s2 = s1; *s2 != ' '; s2++)
                    314:                if(*s2 == '\0'){
                    315:                        more = 0;
                    316:                        *s2 = '\0';
                    317:                        return(s1);
                    318:                }
                    319:        *s2 = '\0';
                    320:        return(s1);
                    321: }

unix.superglobalmegacorp.com

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