void tseg_set_text(tseg_text_t *ts, char *string ) { m_clear( ts->text ); m_write( ts->text, 0, string, strlen(string)+1 ); int ms = ts->m_seg; int ma = ts->m_attr; text_segment_t seg; char *s = string; int a,b,x,attr = 0; while( isspace(*s) ) s++; m_clear( ms ); while(1) { memset(&seg,0,sizeof seg); if( strlist_cut_word(s,&a,&b)) break; if( b-a <= 0 ) break; if( s[b] == '\n' ) seg.format = T_HARD_BREAK; if( s[a] == '@' ) /* attribute prefix found */ { a++; if( s[a] != '@' ) { if( (x = tseg_get_format(ma,s,&a,&b))) seg.format |= x; if( (x=tseg_get_attr(ma, s, &a, &b )) >= 0 ) attr = x; } } seg.start = (s-string)+a; seg.end = (s-string)+b-1; seg.attribute = attr; s+=b; m_put( ms, &seg ); } }
int scan_files( int list, const char *path, void (*get_file_props) (char*path,void *cb), void *cb ) { DIR *dir; struct dirent *entry; dent_t dent; /* struct stat statbuf; */ dir = opendir(path); if(!dir) return 0; while((entry = readdir(dir)) != NULL) { if(strcmp(entry->d_name,".") == 0) continue; if(strcmp(entry->d_name,"..") == 0) continue; if( entry->d_type == DT_DIR ) { dent.subdir=-1; dent.name = strdup(entry->d_name); m_put( list, &dent ); } else if( entry->d_type == DT_REG ) { char *buf; asprintf(&buf,"%s/%s", path, entry->d_name ); get_file_props( buf, cb ); free(buf); } } closedir(dir); return list; }
/** create a child process and connect a pipe to child stdout */ static void child_exec(int hc) { char *null_string = NULL; struct child_stat *child = mls(CLIST, hc); if( pipe2( child->fd, O_NONBLOCK ) ) ERR("pipe2"); if( pipe2( child->fd+2, O_NONBLOCK ) ) ERR("pipe2"); pid_t cpid = fork(); if (cpid == -1) ERR("fork"); if (cpid == 0) { /* Child reads from pipe */ dup2(child->fd[1],1); /* make STDOUT==1 same as WRITE-TO==1 end of pipe-A */ dup2(child->fd[2],0); /* make STDIN==0 sama es READ-FROM==0 end of pipe-B */ xclose(child->fd+0); /* Close unused read end pipe-A */ xclose(child->fd+3); /* Close unused write end pipe-B */ m_put(child->args,&null_string); // execlp( child->filename, child->filename, NULL ); execvp( child->filename, m_buf(child->args) ); m_drop(child->args); perror( "can not exec child process" ); _exit(EXIT_FAILURE); /* never reached */ } xclose( child->fd+1 ); /* close unused WRITE end of pipe-A */ xclose( child->fd+2 ); /* close unused READ end of pipe-B */ child->stat = CHILD_RUNNING; child->pid = cpid; }
int id3db_add( int db, char *path ) { struct id3ent id; id.vs = get_id3_tag(path); if(! id.vs ) return 1; id.path = strdup(path); m_put(db,&id); return 0; }
FUNCTION VOID wrterr ( TEXT msg[], /* IN: error message to output */ TEXT key[], /* IN: message key */ uintptr_t A1, /* IN: integers or string pointers */ uintptr_t A2, uintptr_t A3, uintptr_t A4, uintptr_t A5 ) { IMPORT COUNT termlines; /* number of lines on crt screen */ IMPORT CODE termtype; /* terminal type */ if (termtype == T_CRT) m_cput((termlines - ERRLIN), msg, key, A1, A2, A3, A4, A5); /* write to crt */ else m_put(msg, key, A1, A2, A3, A4, A5); /* write to terminal */ return; }