Annotation of coherent/d/bin/fixstack.c, revision 1.1.1.1

1.1       root        1: /* fix stack on l.out type file
                      2:  * first parm is the amount to add or subtract in hex
                      3:  * the second parm is the l.out file name default "l.out"
                      4:  */
                      5: #include <stdio.h>
                      6: #include <l.out.h>
                      7: #include <canon.h>
                      8: #include <mtype.h>
                      9: main (argc, argv)
                     10: char   *argv[];
                     11: {
                     12:        FILE *lout;
                     13:        char *argp, c, negsw=0;
                     14:        long hexno=0;
                     15: 
                     16:        if(--argc > 0) {
                     17:                argp = *++argv;
                     18:                while((c = *argp++) != '\0') {
                     19:                        switch(c) {
                     20:                                case '-' :
                     21:                                        negsw=1;
                     22:                                        break;
                     23:                                case '+' :
                     24:                                        negsw=0;
                     25:                                        break;
                     26:                                case '0' :
                     27:                                case '1' :
                     28:                                case '2' :
                     29:                                case '3' :
                     30:                                case '4' :
                     31:                                case '5' :
                     32:                                case '6' :
                     33:                                case '7' :
                     34:                                case '8' :
                     35:                                case '9' :
                     36:                                        hexno<<=4;
                     37:                                        hexno+=(c-'0');
                     38:                                        break;
                     39:                                case 'a' :
                     40:                                case 'b' :
                     41:                                case 'c' :
                     42:                                case 'd' :
                     43:                                case 'e' :
                     44:                                case 'f' :
                     45:                                        hexno<<=4;
                     46:                                        hexno+=(c-'a'+10);
                     47:                                        break;
                     48:                                case 'A' :
                     49:                                case 'B' :
                     50:                                case 'C' :
                     51:                                case 'D' :
                     52:                                case 'E' :
                     53:                                case 'F' :
                     54:                                        hexno<<=4;
                     55:                                        hexno+=(c-'A'+10);
                     56:                                        break;
                     57:                                default:
                     58:                                        usage();
                     59:                        }
                     60:                }
                     61:        } else
                     62:                usage();
                     63: 
                     64:        if(negsw)
                     65:                hexno= -hexno;
                     66: 
                     67:        if(--argc > 0)
                     68:                argp=*++argv;
                     69:        else
                     70:                argp="l.out";
                     71: 
                     72:        if(NULL==(lout=fopen(argp, "rw"))) {
                     73:                fprintf(stderr, "fixstack: %s cannot open \n", argp);
                     74:                exit(1);
                     75:        }
                     76: 
                     77:        proscess(hexno, lout, argp);
                     78:        exit(0);
                     79: }
                     80: 
                     81: proscess(hexno, lout, argp)
                     82: long hexno;
                     83: FILE *lout;
                     84: char *argp;
                     85: {
                     86:        long where;
                     87:        struct ldheader head;
                     88: 
                     89:        where=ftell(lout);      /* not zero on some systems */
                     90:        if(0 == (fread(&head, sizeof(head), 1, lout))) {
                     91:                fprintf(stderr, "fixstack: error in read\n");
                     92:                exit(1);
                     93:        }
                     94: 
                     95:        if(fseek(lout, where, 0)) {
                     96:                fprintf(stderr, "fixstack: error in seek\n");
                     97:                exit(1);
                     98:        }
                     99: 
                    100:        canshort(head.l_magic);
                    101:        if(head.l_magic!=L_MAGIC) {
                    102:                fprintf(stderr, "fixstack: %s not an l.out file %x\n",
                    103:                        argp, head.l_magic );
                    104:                exit(1);
                    105:        }
                    106:        
                    107:        cansize(head.l_ssize[L_BSSD]);
                    108:        head.l_ssize[L_BSSD] += hexno;
                    109:        cansize(head.l_ssize[L_BSSD]);
                    110: 
                    111:        if(1 != (fwrite(&head, sizeof(head), 1, lout))) {
                    112:                fprintf(stderr, "fixstack: error in write\n");
                    113:                exit(1);
                    114:        }
                    115: }
                    116: 
                    117: usage()
                    118: {
                    119:        fprintf(stderr, "Usage: fixstack hexno filen.\n");
                    120:        exit(1);
                    121: }

unix.superglobalmegacorp.com

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