move bld scripts to blds, add yuri GL bsd patch
[goodguy/history.git] / cinelerra-5.1 / blds / bsd.patch
1 diff --git a/cinelerra-5.1/Makefile.devel b/cinelerra-5.1/Makefile.devel
2 index a12d8f2b..9aac014a 100644
3 --- a/cinelerra-5.1/Makefile.devel
4 +++ b/cinelerra-5.1/Makefile.devel
5 @@ -4,7 +4,7 @@ TOPDIR := $(CURDIR)
6  CFLAGS ?= -ggdb
7  export CFLAGS_ := $(CFLAGS)
8  
9 -cpus:=$(shell grep -c "^proc" /proc/cpuinfo)
10 +cpus:=$(shell sysctl -n hw.ncpu)
11  jobs:=-j$(shell echo $$(($(cpus) + $(cpus)/2 +2)))
12  MAKEJ := $(MAKE) $(jobs)
13  
14 diff --git a/cinelerra-5.1/cinelerra/Makefile b/cinelerra-5.1/cinelerra/Makefile
15 index 18590e3a..5eead290 100644
16 --- a/cinelerra-5.1/cinelerra/Makefile
17 +++ b/cinelerra-5.1/cinelerra/Makefile
18 @@ -395,6 +395,7 @@ LIBS += -lfontconfig -lfreetype
19  LIBS += -lavcodec -lavdevice -lavfilter -lavformat -lavresample -lavutil
20  LIBS += -lswresample -lswscale
21  LIBS += -lvpx -lwebp -lwebpmux
22 +LIBS += -lintl -liconv -lexecinfo
23  
24  LIBS += $(if $(filter fftw,$(static_pkgs)), -lfftw3)
25  LIBS += $(if $(filter flac,$(static_pkgs)), -lFLAC)
26 @@ -414,7 +415,7 @@ LIBS += $(if $(filter x265,$(static_pkgs)), -lx265)
27  LIBS += $(if $(filter libvpx,$(static_pkgs)), -lvpx)
28  
29  ifneq ($(WANT_GL),no)
30 -LIBS += -lGL -lGLU -lGLX
31 +LIBS += -lGL -lGLU
32  endif
33  ifneq ($(WANT_XFT),no)
34  LIBS += -lXft
35 @@ -476,6 +477,7 @@ LV2OBJS = \
36  endif
37  
38  CFLAGS := \
39 +       -I/usr/local/include \
40         -I$(GUICAST) \
41         -I$(LIBZMPEG3) \
42         $(static_incs) \
43 @@ -523,15 +525,15 @@ all:      $(OUTPUT) $(CUTADS) $(BDWRITE) $(LV2UI)
44  $(OUTPUT): $(OBJS) $(THEME_DATA) $(DCRAW) $(LIBRARIES)
45         $(LINKER) `cat $(OBJDIR)/objs`
46         $(if $(findstring -g,$(CFLAGS)),objcopy --only-keep-debug $(OUTPUT) $(OUTPUT_G))
47 -       $(if $(findstring -ggdb,$(CFLAGS)),,strip $(OUTPUT))
48 +       #$(if $(findstring -ggdb,$(CFLAGS)),,strip $(OUTPUT))
49         ln -f -s ../bin/$(WANT_CIN) ci
50  
51  ifneq ($(WANT_COMMERCIAL),no)
52  $(CUTADS):     $(CUTOBJS) $(CUTLIBS) $(LIBRARIES)
53 -       @echo g++ -o $@ $(CUTOBJS)
54 -       @g++ $(CFLAGS) -pthread -o $@ $(CUTOBJS) $(CUTLIBS) $(LIBS)
55 +       @echo $(CXX) -o $@ $(CUTOBJS)
56 +       @$(CXX) $(CFLAGS) -pthread -o $@ $(CUTOBJS) $(CUTLIBS) $(LIBS)
57         $(if $(findstring -g,$(CFLAGS)),objcopy --only-keep-debug $(CUTADS) $(CUTADS).debuginfo)
58 -       $(if $(findstring -ggdb,$(CFLAGS)),,strip $(CUTADS))
59 +       #$(if $(findstring -ggdb,$(CFLAGS)),,strip $(CUTADS))
60  
61  install-cutads:
62         cp -av $(OBJDIR)/cutads $(BINDIR)/.
63 @@ -540,18 +542,18 @@ install:  install-cutads
64  endif
65  
66  $(BDWRITE):    $(BDWOBJS) $(LIBRARIES)
67 -       @echo g++ -o $@ $(BDWOBJS)
68 -       @g++ $(CFLAGS) -pthread -o $@ $(BDWOBJS) $(LIBS)
69 +       @echo $(CXX) -o $@ $(BDWOBJS)
70 +       @$(CXX) $(CFLAGS) -pthread -o $@ $(BDWOBJS) $(LIBS)
71         $(if $(findstring -g,$(CFLAGS)),objcopy --only-keep-debug $(BDWRITE) $(BDWRITE).debuginfo)
72 -       $(if $(findstring -ggdb,$(CFLAGS)),,strip $(BDWRITE))
73 +       #$(if $(findstring -ggdb,$(CFLAGS)),,strip $(BDWRITE))
74  
75  install-bdwrite:
76         cp -av $(OBJDIR)/bdwrite $(BINDIR)/.
77  install:       install-bdwrite
78  
79  ydiff: ydiff.C $(LIBRARIES)
80 -       @echo g++ -o $@ ydiff.C
81 -       @g++ $(CFLAGS) ydiff.C -o $@ $(LIBS)
82 +       @echo $(CXX) -o $@ ydiff.C
83 +       @$(CXX) $(CFLAGS) ydiff.C -o $@ $(LIBS)
84  
85  clean:
86         rm -rf $(OBJDIR)
87 @@ -585,7 +587,7 @@ $(OBJDIR)/lv2ui: $(LV2OBJS)
88         @echo $(CXX) \`cat $(OBJDIR)/c_flags\` $^ -o $@
89         @$(CXX) `cat $(OBJDIR)/c_flags` $^ -o $@ $(LIBS) $(GTK2_LIBS)
90         $(if $(findstring -g,$(CFLAGS)),objcopy --only-keep-debug $(LV2UI) $(LV2UI).debuginfo)
91 -       $(if $(findstring -ggdb,$(CFLAGS)),,strip $(LV2UI))
92 +       #$(if $(findstring -ggdb,$(CFLAGS)),,strip $(LV2UI))
93  
94  .PHONY:        lv2ui
95  lv2ui: $(LV2UI)
96 diff --git a/cinelerra-5.1/cinelerra/bdcreate.C b/cinelerra-5.1/cinelerra/bdcreate.C
97 index 27f728ad..9215090d 100644
98 --- a/cinelerra-5.1/cinelerra/bdcreate.C
99 +++ b/cinelerra-5.1/cinelerra/bdcreate.C
100 @@ -25,8 +25,8 @@
101  #include <unistd.h>
102  #include <fcntl.h>
103  #include <errno.h>
104 -#include <sys/stat.h>
105 -#include <sys/statfs.h>
106 +#include <sys/param.h>
107 +#include <sys/mount.h>
108  
109  // BD Creation
110  
111 diff --git a/cinelerra-5.1/cinelerra/bdwrite.C b/cinelerra-5.1/cinelerra/bdwrite.C
112 index 6a2b4ca3..78cf9bef 100644
113 --- a/cinelerra-5.1/cinelerra/bdwrite.C
114 +++ b/cinelerra-5.1/cinelerra/bdwrite.C
115 @@ -38,7 +38,7 @@
116  #include <stdint.h>
117  #include <stdlib.h>
118  #include <string.h>
119 -#include <endian.h>
120 +#include <sys/endian.h>
121  #include <limits.h>
122  #include <sys/stat.h>
123  // work arounds (centos)
124 diff --git a/cinelerra-5.1/cinelerra/cutads.C b/cinelerra-5.1/cinelerra/cutads.C
125 index ac58d56a..f6690cf2 100644
126 --- a/cinelerra-5.1/cinelerra/cutads.C
127 +++ b/cinelerra-5.1/cinelerra/cutads.C
128 @@ -23,14 +23,6 @@
129  using namespace std;
130  #define fail(s) do { printf("fail %s%s:%d\n",__func__,#s,__LINE__); return 1; } while(0)
131  
132 -/* missing from system headers, no /usr/include <linux/ioprio.h>
133 - *   IOPRIO_WHO_PROCESS, IOPRIO_CLASS_SHIFT, IOPRIO_CLASS_IDLE */
134 -enum { IOPRIO_CLASS_NONE, IOPRIO_CLASS_RT, IOPRIO_CLASS_BE, IOPRIO_CLASS_IDLE, };
135 -#define IO_CLASS(n) (((int)(n)) << 13)
136 -#define IO_WHO_PROCESS  1
137 -#include <sys/syscall.h>
138 -#include <asm/unistd.h>
139 -
140  // commercial edge detection:
141  // must have audio < min_audio
142  //   and within +- check_margin seconds of low audio
143 @@ -55,11 +47,6 @@ class Video;
144  class Audio;
145  class Scan;
146  
147 -static int ioprio_set(int which, int who, int ioprio)
148 -{
149 -       return syscall(SYS_ioprio_set, which, who, ioprio);
150 -}
151 -
152  static inline int clip(int v, int mn, int mx)
153  {
154    return v<mn ? mn : v>mx ? mx : v;
155 @@ -617,7 +604,6 @@ class Scan
156         const char *asset_path;
157         static void set_priority(int pr, int io) {
158                 setpriority(PRIO_PROCESS, 0, pr);  // lowest cpu priority
159 -               ioprio_set(IO_WHO_PROCESS, 0, IO_CLASS(io));
160         }
161         class low_priority { public:
162                 low_priority() { set_priority(19, IOPRIO_CLASS_IDLE); }
163 diff --git a/cinelerra-5.1/cinelerra/dvdcreate.C b/cinelerra-5.1/cinelerra/dvdcreate.C
164 index 1014baf5..f38094e9 100644
165 --- a/cinelerra-5.1/cinelerra/dvdcreate.C
166 +++ b/cinelerra-5.1/cinelerra/dvdcreate.C
167 @@ -24,8 +24,8 @@
168  #include <unistd.h>
169  #include <fcntl.h>
170  #include <errno.h>
171 -#include <sys/stat.h>
172 -#include <sys/statfs.h>
173 +#include <sys/param.h>
174 +#include <sys/mount.h>
175  
176  
177  #define DVD_PAL_4x3    0
178 diff --git a/cinelerra-5.1/cinelerra/file.C b/cinelerra-5.1/cinelerra/file.C
179 index 03348e0a..552a140d 100644
180 --- a/cinelerra-5.1/cinelerra/file.C
181 +++ b/cinelerra-5.1/cinelerra/file.C
182 @@ -1584,7 +1584,10 @@ int File::record_fd()
183  void File::get_exe_path(char *result, char *bnp)
184  {
185  // Get executable path, basename
186 -       int len = readlink("/proc/self/exe", result, BCTEXTLEN-1);
187 +       char exe_path[BCTEXTLEN];
188 +       sprintf(exe_path,"/proc/%d/file",getpid());
189 +       int len = readlink(exe_path, result, BCTEXTLEN-1);
190 +
191         if( len >= 0 ) {
192                 result[len] = 0;
193                 char *ptr = strrchr(result, '/');
194 diff --git a/cinelerra-5.1/cinelerra/indexfile.C b/cinelerra-5.1/cinelerra/indexfile.C
195 index 3d21d2af..f3064199 100644
196 --- a/cinelerra-5.1/cinelerra/indexfile.C
197 +++ b/cinelerra-5.1/cinelerra/indexfile.C
198 @@ -70,7 +70,7 @@
199  
200  #include <sys/types.h>
201  #include <sys/stat.h>
202 -#include <linux/iso_fs.h>
203 +#include <isofs/cd9660/iso.h>
204  
205  // check for isofs volume_id for dvd/cdrom
206  
207 diff --git a/cinelerra-5.1/configure.ac b/cinelerra-5.1/configure.ac
208 index 94f9b382..4c4bee11 100644
209 --- a/cinelerra-5.1/configure.ac
210 +++ b/cinelerra-5.1/configure.ac
211 @@ -16,15 +16,26 @@ CFG_CFLAGS+=" -Wno-unused-result"
212  CFG_CFLAGS+=" -Wno-stringop-overflow"
213  CFG_CFLAGS+=" -Wno-format-truncation"
214  CFG_CFLAGS+=" -Wno-format-overflow"
215 +CFG_CFLAGS+=" -Wno-unknown-warning-option"
216  CFG_CFLAGS+=" -Wno-parentheses"
217  CFG_CFLAGS+=" -Wno-stringop-truncation"
218 +CFG_CFLAGS+=" -Wno-gnu-designator"
219 +CFG_CFLAGS+=" -Wno-missing-braces"
220 +CFG_CFLAGS+=" -Wno-overloaded-virtual"
221 +CFG_CFLAGS+=" -Wno-self-assign-field"
222 +CFG_CFLAGS+=" -Wno-sometimes-uninitialized"
223 +CFG_CFLAGS+=" -Wno-tautological-pointer-compare"
224 +CFG_CFLAGS+=" -Wno-unused-function"
225 +CFG_CFLAGS+=" -Wno-unused-private-field"
226 +CFG_CFLAGS+=" -Wno-infinite-recursion"
227  CFG_CFLAGS+=" -D__STDC_CONSTANT_MACROS"
228  CFG_CFLAGS+=" -D__STDC_LIMIT_MACROS"
229  CFG_CFLAGS+=" -DPNG_SKIP_SETJMP_CHECK=1"
230  CFG_CFLAGS+=" -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"
231 -CFG_CFLAGS+=" -I/usr/include/freetype2"
232 -CFG_CFLAGS+=" -I/usr/include/uuid"
233 -CFG_CFLAGS+=" -I/usr/include/mjpegtools"
234 +CFG_CFLAGS+=" -I/usr/local/include"
235 +CFG_CFLAGS+=" -I/usr/local/include/freetype2 -I/usr/include/freetype2"
236 +CFG_CFLAGS+=" -I/usr/local/include/uuid -I/usr/include/uuid"
237 +CFG_CFLAGS+=" -I/usr/local/include/mjpegtools -I/usr/include/mjpegtools"
238  
239  AC_DEFUN([CHECK_WITH], [
240  AC_ARG_WITH([$1],
241 @@ -126,7 +137,7 @@ AC_SUBST(MAK_INSTALLS)
242  AC_SUBST(MAK_UNINSTALLS)
243  
244  if test "x$WANT_JOBS" = "xauto"; then
245 -  CPUS=`grep -c "^proc" /proc/cpuinfo`
246 +  CPUS=`sysctl -n hw.ncpu`
247    WANT_JOBS=`expr $CPUS + $CPUS / 2 + 2`
248  fi
249  
250 diff --git a/cinelerra-5.1/db/tdb.h b/cinelerra-5.1/db/tdb.h
251 index 8ee88002..9a17091e 100644
252 --- a/cinelerra-5.1/db/tdb.h
253 +++ b/cinelerra-5.1/db/tdb.h
254 @@ -32,7 +32,7 @@ inline void operator delete[](void *t,size_t n) { free(t); }
255  #endif
256  
257  #define ZMEDIA
258 -#define ZFUTEX
259 +//#define ZFUTEX
260  #ifdef ZFUTEX
261  #include <unistd.h>
262  #include <endian.h>
263 diff --git a/cinelerra-5.1/guicast/bclistbox.h b/cinelerra-5.1/guicast/bclistbox.h
264 index f5994d53..c73169bb 100644
265 --- a/cinelerra-5.1/guicast/bclistbox.h
266 +++ b/cinelerra-5.1/guicast/bclistbox.h
267 @@ -185,7 +185,9 @@ public:
268  
269  // take_focus - used by the suggestion box to keep it from taking focus from the
270  // textbox
271 -       int activate(int take_focus = 1);
272 +       int activate() {  return activate(1); }
273 +       int activate(int take_focus);
274 +
275         int activate(int x, int y, int w=-1, int h=-1);
276         int deactivate();
277         int is_active();
278 diff --git a/cinelerra-5.1/guicast/bcpan.h b/cinelerra-5.1/guicast/bcpan.h
279 index 40f5971f..73d47586 100644
280 --- a/cinelerra-5.1/guicast/bcpan.h
281 +++ b/cinelerra-5.1/guicast/bcpan.h
282 @@ -93,7 +93,8 @@ public:
283                 int &stick_x,
284                 int &stick_y);
285         static int rdtoxy(int &x, int &y, int a, int virtual_r);
286 -       int activate(int popup_x = -1, int popup_y = -1);
287 +       int activate(int popup_x, int popup_y);
288 +       int activate() { return activate(-1,-1); }
289         int deactivate();
290         float* get_values();
291  
292 diff --git a/cinelerra-5.1/guicast/bcresources.C b/cinelerra-5.1/guicast/bcresources.C
293 index e3400600..f201028c 100644
294 --- a/cinelerra-5.1/guicast/bcresources.C
295 +++ b/cinelerra-5.1/guicast/bcresources.C
296 @@ -38,6 +38,7 @@
297  #include <iconv.h>
298  #include <sys/ipc.h>
299  #include <sys/shm.h>
300 +#include <sys/sysctl.h>
301  #include <X11/extensions/XShm.h>
302  #include <fontconfig/fontconfig.h>
303  #include <fontconfig/fcfreetype.h>
304 @@ -297,23 +298,12 @@ int BC_Resources::machine_cpus = 1;
305  
306  int BC_Resources::get_machine_cpus()
307  {
308 -       int cpus = 1;
309 -       FILE *proc = fopen("/proc/cpuinfo", "r");
310 -       if( proc ) {
311 -               char string[BCTEXTLEN], *cp;
312 -               while(!feof(proc) && fgets(string, sizeof(string), proc) ) {
313 -                       if( !strncasecmp(string, "processor", 9) &&
314 -                           (cp = strchr(string, ':')) != 0 ) {
315 -                               int n = atol(cp+1) + 1;
316 -                               if( n > cpus ) cpus = n;
317 -                       }
318 -                       else if( !strncasecmp(string, "cpus detected", 13) &&
319 -                           (cp = strchr(string, ':')) != 0 )
320 -                               cpus = atol(cp+1);
321 -               }
322 -               fclose(proc);
323 -       }
324 -       return cpus;
325 +       int mib[2], ncpu;
326 +       size_t len = sizeof(ncpu);
327 +       mib[0] = CTL_HW;
328 +       mib[1] = HW_NCPU;
329 +       if( sysctl(mib, 2, &ncpu, &len, 0, 0) ) ncpu = 1;
330 +       return ncpu;
331  }
332  
333  void BC_Resources::new_vframes(int n, VFrame *vframes[], ...)
334 @@ -695,7 +685,7 @@ new_vframes(20,default_medium_7segment,
335         generic_button_margin = 15;
336         draw_clock_background=1;
337  
338 -       use_shm = -1;
339 +       use_shm = 0;
340         shm_reply = 1;
341  
342  // Initialize
343 @@ -1681,6 +1671,87 @@ BC_FontEntry *BC_Resources::find_fontentry(const char *displayname, int style,
344         return style_match;
345  }
346  
347 +
348 +class utf8conv {
349 +       uint8_t *obfr, *out, *oend;
350 +       uint8_t *ibfr, *inp, *iend;
351 +public:
352 +       utf8conv(void *out, int olen, void *inp, int ilen) {
353 +               this->obfr = this->out = (uint8_t*)out;
354 +               this->oend = this->out + olen;
355 +               this->ibfr = this->inp = (uint8_t*)inp;
356 +               this->iend = this->inp + ilen;
357 +       }
358 +       int cur() { return inp>=iend ? -1 : *inp; }
359 +       int next() { return inp>=iend ? -1 : *inp++; }
360 +       int next(int ch) { return out>=oend ? -1 : *out++ = ch; }
361 +       int ilen() { return inp-ibfr; }
362 +       int olen() { return out-obfr; }
363 +       int wnext();
364 +       int wnext(unsigned int v);
365 +};
366 +
367 +int utf8conv::
368 +wnext(unsigned int v)
369 +{
370 +  if( v < 0x00000080 ) { next(v);  return 1; }
371 +  int n = v < 0x00000800 ? 2 : v < 0x00010000 ? 3 :
372 +          v < 0x00200000 ? 4 : v < 0x04000000 ? 5 : 6;
373 +  int m = (0xff00 >> n), i = n-1;
374 +  next((v>>(6*i)) | m);
375 +  while( --i >= 0 ) next(((v>>(6*i)) & 0x3f) | 0x80);
376 +  return n;
377 +}
378 +
379 +int utf8conv::
380 +wnext()
381 +{
382 +  int v = 0, n = 0, ch = next();
383 +  if( ch == '\\' ) {
384 +    switch( (ch=next()) ) {
385 +    case 'n': return '\n';
386 +    case 't': return '\t';
387 +    case 'r': return '\r';
388 +    case 'b': return '\b';
389 +    case 'f': return '\f';
390 +    case 'v': return '\v';
391 +    case 'a': return '\a';
392 +    case '0': case '1': case '2': case '3':
393 +    case '4': case '5': case '6': case '7':
394 +      v = ch - '0';
395 +      for( int i=3; --i>0; v=v*8+ch, next() )
396 +        if( (ch=cur()-'0') < 0 || ch >= 8 ) break;
397 +      return v;
398 +    case 'x':  n = 2;  break;
399 +    case 'u':  n = 4;  break;
400 +    case 'U':  n = 8;  break;
401 +    default: return ch;
402 +    }
403 +    for( int i=n; --i>=0; v=v*16+ch, next() ) {
404 +      if( (ch=cur()-'0')>=0 && ch<10 ) continue;
405 +      if( (ch-='A'-'0'-10)>=10 && ch<16 ) continue;
406 +      if( (ch-='a'-'A')<10 || ch>=16 ) break;
407 +    }
408 +  }
409 +  else if( ch >= 0x80 ) {
410 +    static const unsigned char byts[] = {
411 +      1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 4, 5,
412 +    };
413 +    int i = ch - 0xc0;
414 +    n = i<0 ? 0 : byts[i/4];
415 +    for( v=ch, i=n; --i>=0; v+=next() ) v <<= 6;
416 +    static const unsigned int ofs[6] = {
417 +      0x00000000U, 0x00003080U, 0x000E2080U,
418 +      0x03C82080U, 0xFA082080U, 0x82082080U
419 +    };
420 +    v -= ofs[n];
421 +  }
422 +  else
423 +    v = ch;
424 +  return v;
425 +}
426 +
427 +
428  size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
429         char *input, int input_length, char *output, int output_length)
430  {
431 @@ -1688,10 +1759,12 @@ size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
432         iconv_t cd;
433         char *outbase = output;
434  
435 -       if(!from_enc || *from_enc == 0)
436 +       if( !from_enc || *from_enc == 0 ||
437 +           !strcmp(from_enc,"UTF8") || !strcmp(from_enc, "US-ASCII") )
438                 from_enc = "UTF-8";
439  
440 -       if(!to_enc || *to_enc == 0)
441 +       if( !to_enc || *to_enc == 0 ||
442 +           !strcmp(to_enc,"UTF8") || !strcmp(to_enc, "US-ASCII") )
443                 to_enc = "UTF-8";
444  
445         if(input_length < 0)
446 @@ -1701,32 +1774,45 @@ size_t BC_Resources::encode(const char *from_enc, const char *to_enc,
447  
448         if(strcmp(from_enc, to_enc) && inbytes)
449         {
450 -               if((cd = iconv_open(to_enc, from_enc)) == (iconv_t)-1)
451 +               if( !strcmp(from_enc, "UTF-8") && !strcmp(to_enc,"UTF32LE") ) {
452 +                       utf8conv uc(0,0, input,inbytes);
453 +                       uint32_t *op = (uint32_t *)output;
454 +                       uint32_t *ep = (uint32_t *)(output+output_length);
455 +                       for( int wch; op<ep && (wch=uc.wnext())>=0; *op++=wch );
456 +                       output = (char *)op;
457 +                       outbytes = (char*)ep - output;
458 +               }
459 +               else if( !strcmp(from_enc, "UTF32LE") && !strcmp(to_enc,"UTF-8") ) {
460 +                       utf8conv uc(output,output_length, 0,0);
461 +                       uint32_t *ip = (uint32_t *)input;
462 +                       uint32_t *ep = (uint32_t *)(input+inbytes);
463 +                       for( ; ip<ep && uc.wnext(*ip)>=0; ++ip );
464 +                       output += uc.olen();
465 +                       outbytes = output_length-uc.olen();
466 +               }
467 +               else if((cd = iconv_open(to_enc, from_enc)) == (iconv_t)-1)
468                 {
469                         printf(_("Conversion from %s to %s is not available\n"),
470                                 from_enc, to_enc);
471                         return 0;
472                 }
473 -
474 -               outbytes = output_length - 1;
475 -
476 -               iconv(cd, &input, &inbytes, &output, &outbytes);
477 -
478 -               iconv_close(cd);
479 -               inbytes = output - outbase;
480 +               else {
481 +                       outbytes = output_length - 1;
482 +                       iconv(cd, &input, &inbytes, &output, &outbytes);
483 +                       iconv_close(cd);
484 +               }
485         }
486         else if(inbytes)
487         {
488                 memcpy(output,  input, inbytes);
489 +               output += inbytes;
490                 outbytes -= inbytes;
491         }
492 -       for(int i = 0; i < 4; i++)
493 -       {
494 +       if( outbytes > sizeof(uint32_t) )
495 +               outbytes = sizeof(uint32_t);
496 +       for(int i = 0; i < outbytes; i++)
497                 output[i] = 0;
498 -               if(outbytes-- == 0)
499 -                       break;
500 -       }
501 -       return inbytes;
502 +       return output - outbase;
503  }
504  
505  void BC_Resources::encode_to_utf8(char *buffer, int buflen)
506 diff --git a/cinelerra-5.1/guicast/bcsignals.C b/cinelerra-5.1/guicast/bcsignals.C
507 index ed50cfb1..f1b894ba 100644
508 --- a/cinelerra-5.1/guicast/bcsignals.C
509 +++ b/cinelerra-5.1/guicast/bcsignals.C
510 @@ -37,9 +37,11 @@
511  #include <sys/stat.h>
512  #include <unistd.h>
513  #include <sys/ioctl.h>
514 -#include <sys/prctl.h>
515  #include <sys/types.h>
516  
517 +#define dirent64 dirent
518 +#define readdir64 readdir
519 +
520  BC_Signals* BC_Signals::global_signals = 0;
521  static int signal_done = 0;
522  
523 @@ -279,18 +281,6 @@ static void handle_exit(int signum)
524  
525  void BC_Signals::set_sighup_exit(int enable)
526  {
527 -       if( enable ) {
528 -// causes SIGHUP to be generated when parent dies
529 -               signal(SIGHUP, handle_exit);
530 -               prctl(PR_SET_PDEATHSIG, SIGHUP, 0,0,0);
531 -// prevents ^C from signalling child when attached to gdb
532 -               setpgid(0, 0);
533 -               if( isatty(0) ) ioctl(0, TIOCNOTTY, 0);
534 -       }
535 -       else {
536 -               signal(SIGHUP, signal_entry);
537 -               prctl(PR_SET_PDEATHSIG, 0,0,0,0);
538 -       }
539  }
540  
541  BC_Signals::BC_Signals()
542 @@ -383,11 +373,13 @@ const char* BC_Signals::sig_to_str(int number)
543  #include <sys/wait.h>
544  #include "thread.h"
545  
546 +#define SC_(r)sc_##r
547 +
548  #if __i386__
549 -#define IP eip
550 +#define IP SC_(eip)
551  #endif
552  #if __x86_64__
553 -#define IP rip
554 +#define IP SC_(rip)
555  #endif
556  #ifndef IP
557  #error gotta have IP
558 @@ -473,26 +465,5 @@ static void handle_dump(int n, siginfo_t * info, void *sc)
559  
560         fprintf(fp,"\n\n");
561         if( fp != stdout ) fclose(fp);
562 -       char cmd[1024], *cp = cmd;
563 -       cp += sprintf(cp, "exec gdb /proc/%d/exe -p %d --batch --quiet "
564 -               "-ex \"thread apply all info registers\" "
565 -               "-ex \"thread apply all bt full\" "
566 -               "-ex \"quit\"", pid, pid);
567 -       if( fp != stdout )
568 -               cp += sprintf(cp," >> \"%s\"", fn);
569 -       cp += sprintf(cp," 2>&1");
570 -//printf("handle_dump:: pid=%d, cmd='%s'  fn='%s'\n",pid,cmd,fn);
571 -        pid = vfork();
572 -        if( pid < 0 ) {
573 -               fprintf(stderr,"** can't start gdb, dump abondoned\n");
574 -               return;
575 -       }
576 -       if( pid > 0 ) {
577 -               waitpid(pid,0,0);
578 -               fprintf(stderr,"** dump complete\n");
579 -               return;
580 -       }
581 -        char *const argv[4] = { (char*) "/bin/sh", (char*) "-c", cmd, 0 };
582 -        execvp(argv[0], &argv[0]);
583  }
584  
585 diff --git a/cinelerra-5.1/guicast/filesystem.C b/cinelerra-5.1/guicast/filesystem.C
586 index ebc2007d..9d6452cb 100644
587 --- a/cinelerra-5.1/guicast/filesystem.C
588 +++ b/cinelerra-5.1/guicast/filesystem.C
589 @@ -33,6 +33,8 @@
590  #include <unistd.h>
591  #include <utime.h>
592  
593 +#define dirent64 dirent
594 +#define readdir64 readdir
595  
596  #include "filesystem.h"
597  
598 diff --git a/cinelerra-5.1/guicast/thread.C b/cinelerra-5.1/guicast/thread.C
599 index dff53e61..321ab4fc 100644
600 --- a/cinelerra-5.1/guicast/thread.C
601 +++ b/cinelerra-5.1/guicast/thread.C
602 @@ -55,13 +55,6 @@ void* Thread::entrypoint(void *parameters)
603         pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
604         thread->cancel_enabled = false;
605  
606 -// Set realtime here seince it doesn't work in start
607 -       if( thread->realtime && getuid() == 0 ) {
608 -               struct sched_param param = { sched_priority : 1 };
609 -               if(pthread_setschedparam(thread->tid, SCHED_RR, &param) < 0)
610 -                       perror("Thread::entrypoint pthread_attr_setschedpolicy");
611 -       }
612 -
613         thread->run();
614         thread->finished = true;
615         if( !thread->synchronous ) {
616 diff --git a/cinelerra-5.1/guicast/thread.h b/cinelerra-5.1/guicast/thread.h
617 index 216ecd2b..8ebec237 100644
618 --- a/cinelerra-5.1/guicast/thread.h
619 +++ b/cinelerra-5.1/guicast/thread.h
620 @@ -27,7 +27,7 @@
621  #include <unistd.h>
622  #include <sys/syscall.h>
623  
624 -static inline int gettid() { return syscall(SYS_gettid, 0, 0, 0); }
625 +static inline long gettid() { return (long)pthread_self(); }
626  
627  // The thread does not autodelete by default.
628  // If autodelete is 1 the thread autodeletes.
629 diff --git a/cinelerra-5.1/plugins/Makefile b/cinelerra-5.1/plugins/Makefile
630 index 6ed357c7..56081181 100644
631 --- a/cinelerra-5.1/plugins/Makefile
632 +++ b/cinelerra-5.1/plugins/Makefile
633 @@ -31,7 +31,6 @@ DIRS = $(OPENCV_OBJS) \
634         brightness \
635         burn \
636         C41 \
637 -       cdripper \
638         chromakey \
639         chromakeyhsv \
640         color3way \
641 @@ -161,6 +160,8 @@ DIRS = $(OPENCV_OBJS) \
642  #      denoisemjpeg \
643  # duplicate
644  #      vocoder \
645 +# not in bsd
646 +#      cdripper \
647  
648  PLUGIN_DIR = $(BINDIR)/plugins
649  DATA = $(PLUGIN_DIR)/fonts $(PLUGIN_DIR)/shapes
650 diff --git a/cinelerra-5.1/plugins/titler/titler.C b/cinelerra-5.1/plugins/titler/titler.C
651 index fefbbdb1..045e96d4 100644
652 --- a/cinelerra-5.1/plugins/titler/titler.C
653 +++ b/cinelerra-5.1/plugins/titler/titler.C
654 @@ -57,8 +57,7 @@
655  #include <stdint.h>
656  #include <stdio.h>
657  #include <string.h>
658 -#include <endian.h>
659 -#include <byteswap.h>
660 +#include <sys/endian.h>
661  #include <iconv.h>
662  #include <sys/stat.h>
663  #include <fontconfig/fontconfig.h>