void getmess() { int match; if (slurpclose(0,&message,1024) == -1) die_read(); strnum[fmt_uint(strnum,message.len)] = 0; if (!stralloc_copys(&beforemessage,strnum)) nomem(); if (!stralloc_cats(&beforemessage,":")) nomem(); if (!stralloc_copys(&aftermessage,",")) nomem(); if (getln(&envelope,&line,&match,'\0') == -1) die_read(); if (!match) die_format(); if (line.len < 2) die_format(); if (line.s[0] != 'F') die_format(); strnum[fmt_uint(strnum,line.len - 2)] = 0; if (!stralloc_cats(&aftermessage,strnum)) nomem(); if (!stralloc_cats(&aftermessage,":")) nomem(); if (!stralloc_catb(&aftermessage,line.s + 1,line.len - 2)) nomem(); if (!stralloc_cats(&aftermessage,",")) nomem(); for (;;) { if (getln(&envelope,&line,&match,'\0') == -1) die_read(); if (!match) die_format(); if (line.len < 2) break; if (line.s[0] != 'T') die_format(); strnum[fmt_uint(strnum,line.len - 2)] = 0; if (!stralloc_cats(&aftermessage,strnum)) nomem(); if (!stralloc_cats(&aftermessage,":")) nomem(); if (!stralloc_catb(&aftermessage,line.s + 1,line.len - 2)) nomem(); if (!stralloc_cats(&aftermessage,",")) nomem(); } }
/* Check if a given artist is banned completely (it appears in "~/.shell-fm/autoban"). */ int banned(const char * artist) { FILE * fd; signed match = 0; char * line = NULL; unsigned int size = 0; if(!artist) return 0; if(!(fd = fopen(rcpath("autoban"), "r"))) return 0; while(!feof(fd) && !match) { char * ptr; if(!getln(& line, & size, fd)) continue; if(strlen(line) > 1) { if((ptr = strrchr(line, 10)) != NULL) * ptr = (char) 0; match = (strlen(line) == strlen(artist)) && !strncasecmp(line, artist, strlen(line)); } } if(line) free(line); fclose(fd); return match; }
void get(stralloc *sa) { int match; if (getln(subfdin,sa,&match,'\n') == -1) strerr_die2sys(111,FATAL,MSG(ERR_READ_INPUT)); if (!match) _exit(0); }
int main(int argc, char* args[]) { char epath[512]; char instr[512]; cd("ibin"); while(1) { getExecPath(epath); printf("$%s> ", epath); getln(instr); char* cmd = strtoknc(instr, " "); if(cmd != 0) { char* pargs[64]; int n = 0; do { pargs[n] = strtoknc(0, " "); } while(pargs[n++] != 0); fsexec(cmd, pargs, 0, 0, 0); printf("\n"); } } return 0; }
int main() { int c; /* current character */ int len; /* current line length */ int max; /* maximum length seen so far */ char line[MAXLINE]; /* current input line */ char longest[MAXLINE]; /* longest line saved here */ max = 0; while ((len = getln(line, MAXLINE)) > 0) { if (line[len-1] != '\n') { while ((c=getchar()) !=EOF) { ++len; } } if (len > 80) { printf("%s", line); } if (len > max) { max = len; copy(longest, line); } } if (max > 0) { /* there was a line */ printf("%d, %s", max, longest); /* print line, length including new line */ } return 0; }
void doit() { char ch; int match = 1; long linenum = 0; stralloc fifoline = { 0 }; linenum = 0; /* try duming data in 23 seconds */ alarm(dumpfreq); buffer_putsflush(buffer_2, ARGV0 "entering main loop\n"); /* forever read from pipe line by line and handle it */ while(1) { while(match) { if(flagdumpasap == 1) dumpcheck(flagdumpasap, flagchanged, flagchildrunning, flagsighup); ++linenum; if(buffer_get(&wr, &ch, 1) == 1) { if(getln(&wr, &fifoline, &match, '\n') == -1) continue; buffer_put(buffer_2, &ch, 1); buffer_putflush(buffer_2, fifoline.s, fifoline.len); handle_line(&fifoline, ch); } } } }
char *with_quotes(t_info *all, char **line, int len, char *res) { char *tmp; while ((*line)[len] != '\"') { if (((*line)[len] == '\0')) { (*line)[len] = '\n'; tmp = my_strncpy(*line, len + 1); res = my_strcat(res, tmp); *line = getln(all); len = 0; all->line++; if (*line == NULL) return (res); } else len++; } tmp = my_strncpy(*line, len + 1); res = my_strcat(res, tmp); if ((*line)[len + 1] != '\0') *line = &((*line)[len + 1]); else *line = NULL; return (res); }
int main() { char line[MAXLINE]; while(getln(line, MAXLINE) > 0) printf("%s", line); return 0; }
void read_passwd(void) { if (!password.len) { buffer_init(&b,buffer_unixread,3,bspace,sizeof bspace); if (getln(&b,&password,&match,'\0') == -1) strerr_die2sys(111,FATAL,"unable to read password: "); close(3); if (match) --password.len; } }
int readlines(char *lines[], int maxline){ int i = 0, n; char *p = data; while(i < maxline && (n = getln(p, MAXLEN)) > 0){ lines[i++] = p; p += n; } return i; }
static int getsa(buffer *b,stralloc *sa,int *match) { if (!*match) return 0; if (getln(b,sa,match,'\n') == -1) return -1; if (*match) return 1; if (!sa->len) return 0; if (!stralloc_append(sa,"\n")) return -1; return 1; }
int main() { int len; char line[MAXLINE]; while ((len = getln(line, MAXLINE)) > 0) { reverse(line, len); printf("%s", line); } return 0; }
/* getop: get next character or numeric operand*/ int getop(char s[]) { int i,c; if(line[k]=='\0') if (getln(line,MAX) == 0) return EOF; else k=0; while ((s[0] = c = line[k++]) == ' ' || c == '\t') ; s[1] = '\0'; i=0; if (islower(c)){ while (islower(s[++i] = c = line[k++])) ; s[i]='\0'; if(strlen(s)>1) return MATH; else return s[i-1]; } if (!isdigit (c) && c!='-' && c!='.'/* && !islower(c)*/) return c; /* not a number */ if ( c=='-')/* collect integer part */ if ( isdigit(c =line[k++])|| c == '.') s[++i]=c; else{ return '-'; } if (isdigit(c)) /* collect integer part */ while (isdigit(s[++i] = c = line[k++])) ; if (c == '.') while(isdigit(s[++i] = c = line[k++])) ; s[i] = '\0'; k--; return NUMBER; /* i=0; if (isalpha(c=getch())) while (isalpha(s[++i] = (c = getch()))) ; s[i]='\0'; if (c != EOF) ungetch(c); return MATH;*/ }
void sckif(int timeout, int sck) { /* If the given socket is -1, try both sockets, unix and tcp. */ if(sck == -1) { if(stcpsck != -1) sckif(timeout, stcpsck); if(sunixsck != -1) sckif(timeout, sunixsck); return; } signal(SIGPIPE, SIG_IGN); if(waitread(sck, timeout, 0)) { struct sockaddr client; socklen_t scksize = sizeof(struct sockaddr); int csck = accept(sck, & client, & scksize); if(-1 != csck) { if(waitread(csck, 0, 100000)) { FILE * fd = fdopen(csck, "r"); if(fd) { char * line = NULL, * ptr = NULL, reply[REPLYBUFSIZE]; unsigned size = 0; getln(& line, & size, fd); if(line && size > 0 && !ferror(fd)) { if((ptr = strchr(line, 13)) || (ptr = strchr(line, 10))) * ptr = 0; execcmd(line, reply); } if(line) free(line); if(strlen(reply)) { write(csck, reply, strlen(reply)); } fclose(fd); } } shutdown(csck, SHUT_RDWR); close(csck); } } }
int main() { char line[MAXLINE]; getln(line, MAXLINE); decomment(line); printf("%s", line); return 0; }
int main() { int i; char line[MAXLINE]; getln(line, MAXLINE); nfp(line); printf("%s", line); return 0; }
int main() { char ** args; //commands and arguments char cwd[1024]; while( 1 ) { //infinte input loop getcwd( cwd, sizeof(cwd)); printf("%s $/> ", cwd); args = getln(); if ( argc_get( args ) > 0 ) execute( args ); } }
main() { char line[MAXLN]; while (getln(line, MAXLN) > 0) { strip(line); if (line[0] != '\0') printf("%s\n", line); } return 0; }
const char *get_from(const char *adr, /* target address */ const char *act) /* action */ /* If we captured a from line, it will be from the subscriber, except */ /* when -S is used when it's usually from the subscriber, but of course */ /* could be from anyone. The matching to stored data is required only */ /* to support moderated lists, and in cases where a new -sc is issued */ /* because an old one was invalid. In this case, we read through the */ /* from file trying to match up a timestamp with that starting in */ /* *(act+3). If the time stamp matches, we compare the target address */ /* itself. act + 3 must be a legal part of the string returns pointer to*/ /* fromline, NULL if not found. Since the execution time from when to */ /* storage may differ, we can't assume that the timestamps are in order.*/ { int fd; const char *fl; unsigned int pos; unsigned long thistime; unsigned long linetime; if (!flagstorefrom) return 0; if (fromline.len) { /* easy! We got it in this message */ stralloc_0(&fromline); return fromline.s; } /* need to recover it from DIR/from */ fl = 0; (void) scan_ulong(act+3,&thistime); if ((fd = open_read("from")) == -1) { if (errno == error_noent) return 0; else strerr_die2sys(111,FATAL,MSG1(ERR_READ,"from")); } substdio_fdbuf(&sstext,read,fd,textbuf,(int) sizeof(textbuf)); for (;;) { if (getln(&sstext,&fromline,&match,'\n') == -1) strerr_die2sys(111,FATAL,MSG1(ERR_READ,"from")); if (!match) break; fromline.s[fromline.len - 1] = (char) 0; /* now:time addr\0fromline\0 read all. They can be out of order! */ pos = scan_ulong(fromline.s,&linetime); if (linetime != thistime) continue; if (!str_diff(fromline.s + pos + 1,adr)) { pos = str_len(fromline.s); if (pos < fromline.len) { fl = fromline.s + pos + 1; break; } } } close(fd); return fl; }
/********************************************************************* * HEX file を読み込んで flash_buf[] に格納する. ********************************************************************* */ int read_hexfile(char *fname) { FILE *ifp; int rc; Ropen(fname); while(1) { rc = getln(lnbuf,ifp); read_ihex(lnbuf); if(rc == EOF) break; } Rclose(); return 0; }
void main(){ int len=0; extern char str_arr[]; while( (len =(getln())) >0){ if(len >=MAXLEN){ printf("\n len=%d\n",len); puts(str_arr); } } }
int main(int argc,char *argv[]) { const char* dir; int fd; int match; unsigned long msgsize = 0L; int opt; while ((opt = getopt(argc,argv,"vV")) != opteof) { switch(opt) { case 'v': case 'V': strerr_die2x(0, "ezmlm-import version: ",auto_version); default: die_usage(); } } if (argc - optind != 2) die_usage(); if ((fd = open_read(argv[optind+1])) == -1) strerr_die4sys(111,FATAL,ERR_OPEN,argv[optind+1],": "); substdio_fdbuf(&ssin,read,fd,inputbuf,sizeof inputbuf); startup(dir = argv[optind]); lockfile("lock"); getconf_ulong2(&msgnum,&cumsize,"num",0,dir); fd = 0; while (getln(&ssin,&line,&match,'\n') == 0 && match) { if (line.len > 5 && byte_diff(line.s,5,"From ") == 0) { if (fd > 0) { if (substdio_flush(&ssarchive) == -1 || fchmod(fd,MODE_ARCHIVE|0700) == -1 || close(fd) == -1) strerr_die4sys(111,FATAL,ERR_WRITE,fnaf.s,": "); fd = 0; } ++msgnum; cumsize += (msgsize + 128L) >> 8; msgsize = 0L; fd = openone(msgnum); } else if (fd > 0) { substdio_put(&ssarchive,line.s,line.len); msgsize += line.len; } }
main() { int len; char line[MAXLINE]; char nwln[MAXLINE]; while(len=(getln(line,MAXLINE))>3){ copy(nwln,line); printf("%s\n",nwln); } return 0; }
int main (){ char line[MAX_LINE]; char cleanLine[MAX_LINE]; int len; while ( (len = getln(line, MAX_LINE)) > 0 ) { printf("\nLine::: %s",line); detab(line, cleanLine, len); printf("\nDETAB:: %s",cleanLine); } return 0; }
void store_from(stralloc *frl, /* from line */ const char *adr) /* rewrites the from file removing all that is older than 1000000 secs */ /* and add the curent from line (frl). Forget it if there is none there.*/ /* NOTE: This is used only for subscribes to moderated lists! */ { int fdin; int fdout; unsigned long linetime; if (!flagstorefrom || !frl->len) return; /* nothing to store */ lock(); if ((fdout = open_trunc("fromn")) == -1) strerr_die2sys(111,FATAL,MSG1(ERR_OPEN,"fromn")); substdio_fdbuf(&ssfrom,write,fdout,frombuf,(int) sizeof(frombuf)); if ((fdin = open_read("from")) == -1) { if (errno != error_noent) strerr_die2sys(111,FATAL,MSG1(ERR_OPEN,"from")); } else { substdio_fdbuf(&sstext,read,fdin,textbuf,(int) sizeof(textbuf)); for (;;) { if (getln(&sstext,&line,&match,'\n') == -1) strerr_die2sys(111,FATAL,MSG1(ERR_READ,"from")); if (!match) break; (void) scan_ulong(line.s,&linetime); if (linetime + 1000000 > (unsigned long) when && linetime <= (unsigned long) when) if (substdio_bput(&ssfrom,line.s,line.len)) strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,"fromn")); } close(fdin); } /* build new entry */ stralloc_copyb(&line,strnum,fmt_ulong(strnum,when)); stralloc_append(&line,' '); stralloc_cats(&line,adr); stralloc_0(&line); stralloc_catb(&line,frl->s,frl->len); stralloc_append(&line,'\n'); if (substdio_bput(&ssfrom,line.s,line.len) == -1) strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,"fromn")); if (substdio_flush(&ssfrom) == -1) strerr_die2sys(111,FATAL,MSG1(ERR_WRITE,"fromn")); if (fsync(fdout) == -1) strerr_die2sys(111,FATAL,MSG1(ERR_SYNC,"fromn")); if (close(fdout) == -1) strerr_die2sys(111,FATAL,MSG1(ERR_CLOSE,"fromn")); wrap_rename("fromn","from"); unlock(); }
int getfile(const char *prompt, int mode) { int fd; char buf[100]; do { printf("%s: ", prompt); getln(buf, sizeof buf); if (buf[0] == CTRL('d') && buf[1] == 0) return (-1); } while ((fd = open(buf, mode)) < 0); return (fd); }
int main() { char line[MAX_LINE]; int len; while ((len = getln(line,MAX_LINE)) > 0) { reverse(line,len); printf("%s",line); } // printf("%s",string); return 0; }
void setclen(register struct message *mp) { long c; FILE *ibuf; char line[LINESIZE]; int fline, nread; ibuf = setinput(mp); c = mp->m_size; fline = 1; while (c > 0L) { nread = getln(line, sizeof (line), ibuf); c -= nread; /* * First line is the From line, so no headers * there to worry about. */ if (fline) { fline = 0; continue; } /* * If line is blank, we've reached end of headers. */ if (line[0] == '\n') break; /* * If this line is a continuation * of a previous header field, keep going. */ if (isspace(line[0])) continue; /* * If we are no longer looking at real * header lines, we're done. * This happens in uucp style mail where * there are no headers at all. */ if (!headerp(line)) { c += nread; break; } } if (c == 0) c = 1; mp->m_clen = c; }
void init_conf (irc_t * irc, FILE * conf) { char *servname = NULL, *servport = NULL, *line = NULL, *tok = NULL, ch = 0; int state = 0; do { line = getln(conf); ch = 0; tok = NULL; if (line != NULL) tok = strtok(line, " :"); if (tok != NULL) { if (strcmp(tok, "") == 0) tok = NULL; if (tok != NULL) ch = tok[0]; } if (ch == '{') { state = 1; } else if (ch == '}') { state = 0; } else if (state == 0 && tok != NULL) { servname = tok; servport = strtok(NULL, " :"); if ( irc_connect(irc, servname, servport) < 0 ) { fprintf(stderr, "Connection to %s:%sfailed.\n", servname, servport); } else { if ( irc_login(irc, BOTNAME) < 0 ) { fprintf(stderr, "Couldn't log in.\n"); } } } else if (state == 1 && ch == '#') { char *chan = malloc(strlen(tok)+1); strcpy(chan, tok); irc_join(irc, chan); } if (line != NULL) { free(line); } } while (line != NULL); }
int main(){ char *p, c; int r, g=0, x, i = 0, j = 9999, vla; printf("Guess Number! Ver. 1.0 (%d-%d)\n",i ,j); srand(time(NULL)); r = (rand()%(j+1)); p = (char*)malloc(sizeof(char)); while(1){ getln(p,&vla); g=0; for(x = 0; x <= vla ; x++){ g = g*10 + p[x]-48; } if(g > r){ printf("Smaller!\n"); if( j > g) j = g; }else if(g < r){ printf("Bigger!\n"); if( i < g) i = g; }else{ printf("You Win!\n"); while(1){ i = 0; j = 9999; p = (char*)realloc(p, sizeof(char)); vla=-1; r = (rand()%(j+1)); printf("Continue?(Y\\N)"); c = getchar(); if( c == 121 || c == 89 ){ break; } else if( c == 78 || c == 110) return 0; } } printf("\nGuess Number!(%d-%d)\n",i ,j); } }