char *dup(char *input, int *dict) { char *output = malloc(strlen(input)+1); int i, outpt = 0; for(i=0; i<strlen(input); i++) if(dict[input[i]-'A']>1) output[outpt++]=input[i]; output[outpt] = '\0'; int ndict[26]; memset(ndict, 0, 26*sizeof(int)); return nodup(output, ndict); }
int main(int argc, char **argv) { int i; if(argc!=2) exit(1); char *string = *(argv+1); int *dict = genccountdict(string); for(i = 0; i < strlen(string); i++) string[i] = toupper(string[i]); printf("nodup: %s\n", nodup(string, dict)); printf("nnodup: %s\n", nnodup(string, dict)); printf("dup: %s\n", dup(string, dict)); return 0; }
int main(int argc, char **argv) { int i, c, status; char *s; char fortfile[20], *t; char buff[100]; diagfile = stderr; sigivalue = (int) signal(SIGINT, SIG_IGN) & 01; sigqvalue = (int) signal(SIGQUIT, SIG_IGN) & 01; enbint(intrupt); pid = getpid(); crfnames(); loadargs = (char **)calloc(1, (argc + 20) * sizeof(*loadargs)); if (!loadargs) fatal1("out of memory"); loadp = loadargs; --argc; ++argv; while(argc>0 && argv[0][0]=='-' && argv[0][1]!='\0') { for(s = argv[0]+1 ; *s ; ++s) switch(*s) { case 'T': /* use special passes */ switch(*++s) { case '1': fcom = s+1; goto endfor; case 'a': asmname = s+1; goto endfor; case 'l': ldname = s+1; goto endfor; case 'm': macroname = s+1; goto endfor; default: fatal1("bad option -T%c", *s); } break; case 'w': /* F66 warn or no warn */ addarg(ffary, &ffmax, s-1); break; case 'q': /* * Suppress printing of procedure names during * compilation. */ addarg(ffary, &ffmax, s-1); break; copyfflag: case 'u': case 'U': case 'M': case '1': case 'C': addarg(ffary, &ffmax, s-1); break; case 'O': optimflag = YES; addarg(ffary, &ffmax, s-1); break; case 'm': if(s[1] == '4') ++s; macroflag = YES; break; case 'S': saveasmflag = YES; case 'c': loadflag = NO; break; case 'v': verbose = YES; break; case 'd': debugflag = YES; goto copyfflag; case 'p': profileflag = YES; goto copyfflag; case 'o': if(!strcmp(s, "onetrip")) { addarg(ffary, &ffmax, s-1); goto endfor; } oflag = 1; aoutname = *++argv; --argc; break; case 'F': fortonly = YES; loadflag = NO; break; case 'I': if(s[1]=='2' || s[1]=='4' || s[1]=='s') goto copyfflag; fprintf(diagfile, "invalid flag -I%c\n", s[1]); done(1); case 'l': /* letter ell--library */ s[-1] = '-'; *loadp++ = s-1; goto endfor; case 'E': /* EFL flag argument */ while(( *eflagp++ = *++s)) ; *eflagp++ = ' '; goto endfor; case 'R': while(( *rflagp++ = *++s )) ; *rflagp++ = ' '; goto endfor; default: lflag[1] = *s; *loadp++ = copyn(strlen(lflag), lflag); break; } endfor: --argc; ++argv; } if (verbose) fprintf(stderr, xxxvers); if (argc == 0) errorx("No input files"); #ifdef mach_pdp11 if(nofloating) *loadp++ = (profileflag ? NOFLPROF : NOFLFOOT); else #endif for(i = 0 ; i<argc ; ++i) switch(c = dotchar(infname = argv[i]) ) { case 'r': /* Ratfor file */ case 'e': /* EFL file */ if( unreadable(argv[i]) ) break; s = fortfile; t = lastfield(argv[i]); while(( *s++ = *t++)) ; s[-2] = 'f'; if(macroflag) { snprintf(buff, sizeof(buff), "%s %s >%s", macroname, infname, prepfname); if(sys(buff)) { rmf(prepfname); break; } infname = prepfname; } if(c == 'e') snprintf(buff, sizeof(buff), "efl %s %s >%s", eflags, infname, fortfile); else snprintf(buff, sizeof(buff), "ratfor %s %s >%s", rflags, infname, fortfile); status = sys(buff); if(macroflag) rmf(infname); if(status) { loadflag = NO; rmf(fortfile); break; } if( ! fortonly ) { infname = argv[i] = lastfield(argv[i]); *lastchar(infname) = 'f'; if( dofort(argv[i]) ) loadflag = NO; else { if( nodup(t = setdoto(argv[i])) ) *loadp++ = t; rmf(fortfile); } } break; case 'f': /* Fortran file */ case 'F': if( unreadable(argv[i]) ) break; if( dofort(argv[i]) ) loadflag = NO; else if( nodup(t=setdoto(argv[i])) ) *loadp++ = t; break; case 'c': /* C file */ case 's': /* Assembler file */ if( unreadable(argv[i]) ) break; fprintf(diagfile, "%s:\n", argv[i]); snprintf(buff, sizeof(buff), "cc -c %s", argv[i]); if( sys(buff) ) loadflag = NO; else if( nodup(t = setdoto(argv[i])) ) *loadp++ = t; break; case 'o': if( nodup(argv[i]) ) *loadp++ = argv[i]; break; default: if( ! strcmp(argv[i], "-o") ) aoutname = argv[++i]; else *loadp++ = argv[i]; break; } if(loadflag) doload(loadargs, loadp); done(0); return 0; }