[MPlayer-users] (lack of) code style

Denis Vlasenko vda.linux at googlemail.com
Sat Aug 19 20:18:54 CEST 2006


Hello,

I took a look into mplayer source.
Well. I saw sources of quite a number of open-source
projects, and mplayer is definitely won't make to the
"cleanest code" award.

Two random examples:

mplayer.c:3092

    if(filename) mp_msg(MSGT_CPLAYER,MSGL_INFO,MSGTR_Playing, filename);

if (edl_filename) {
    if (edl_records) free_edl(edl_records);
    next_edl_record = edl_records = edl_parse_file();
}
if (edl_output_filename) {
    if (edl_fd) fclose(edl_fd);
    if ((edl_fd = fopen(edl_output_filename, "w")) == NULL)
    {
        mp_msg(MSGT_CPLAYER, MSGL_ERR, MSGTR_EdlCantOpenForWrite,
               edl_output_filename);
    }
}

What is going on with the indentation here?
Entire mplayer.c is littered with similar things.

stream/stream.h:215

inline static unsigned char* stream_read_line(stream_t *s,unsigned char* mem, int max) {
  int len;
  unsigned char* end,*ptr = mem;;
  do {
    len = s->buf_len-s->buf_pos;
    // try to fill the buffer
    if(len <= 0 &&
       (!cache_stream_fill_buffer(s) ||
        (len = s->buf_len-s->buf_pos) <= 0)) break;
    end = (unsigned char*) memchr((void*)(s->buffer+s->buf_pos),'\n',len);
    if(end) len = end - (s->buffer+s->buf_pos) + 1;
    if(len > 0 && max > 1) {
      int l = len > max-1 ? max-1 : len;
      memcpy(ptr,s->buffer+s->buf_pos,l);
      max -= l;
      ptr += l;
    }
    s->buf_pos += len;
  } while(!end);
  if(s->eof && ptr == mem) return NULL;
  if(max > 0) ptr[0] = 0;
  return mem;
}

Gross code duplication due to excessive inlining.

This is my impression from just a 5-minute cursory
examination, so maybe I had an extremely bad luck
of hitting the worst places to look at.
--
vda



More information about the MPlayer-users mailing list