Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 21932 | Differences between
and this patch

Collapse All | Expand All

(-)chkfontpath.c.orig (-5 / +256 lines)
Lines 36-45 Link Here
36
#define XFS_CONFIGBACKUP	"/etc/X11/fs/config-"
36
#define XFS_CONFIGBACKUP	"/etc/X11/fs/config-"
37
#define XFS_PIDFILE		"/var/run/xfs.pid"
37
#define XFS_PIDFILE		"/var/run/xfs.pid"
38
#define XFS_SUBSYSLOCK		"/var/lock/subsys/xfs"
38
#define XFS_SUBSYSLOCK		"/var/lock/subsys/xfs"
39
#define XF86_CONFIGFILE		"/etc/X11/XF86Config"
40
#define XF86_CONFIGBACKUP	"/etc/X11/XF86Config-"
39
41
40
static char *progName;
42
static char *progName;
41
static const char **fpList;
43
static const char **fpList;
42
static int fpCount;
44
static int fpCount;
45
static const char **fpListXF86;
46
static int fpCountXF86;
43
static int quiet;
47
static int quiet;
44
static int firstdir;
48
static int firstdir;
45
49
Lines 55-60 Link Here
55
  exit((quiet) ? EXIT_SUCCESS : EXIT_FAILURE);
59
  exit((quiet) ? EXIT_SUCCESS : EXIT_FAILURE);
56
}
60
}
57
61
62
63
void fatalwarn(const char *format, ...)
64
{
65
  va_list args;
66
 
67
  if(!quiet) {
68
    va_start(args, format);
69
    vfprintf(stderr, format, args);
70
    va_end(args);
71
  }
72
}
73
74
58
void readFontPath(void)
75
void readFontPath(void)
59
{
76
{
60
  FILE *f;
77
  FILE *f;
Lines 137-142 Link Here
137
  fclose(f);
154
  fclose(f);
138
}
155
}
139
156
157
void readFontPathXF86()
158
{
159
  FILE *f;
160
  char buf[250];
161
  char *s, *p, *q;
162
163
  if (NULL == (f = fopen(XF86_CONFIGFILE, "r")))
164
    fatalerror("%s: error opening %s\n", progName, XF86_CONFIGFILE);
165
166
  while ((q = s = fgets(buf, sizeof(buf), f)) != NULL) {
167
    p = s;
168
169
    /* strip leading white space */
170
    while (isblank(*s)) s++;
171
    /* strip trailing white space */
172
    p = s + strlen(s)-2;
173
    while (isspace(*p)) {
174
      *p = '\0';
175
      p--;
176
    }
177
    *(p+1) = '\n';
178
    *(p+2) = '\0';
179
    
180
    /* skip all comment lines */
181
    if (*s == '#')
182
      continue;
183
184
    /* find the FontPath line */
185
    if (strstr(s, "FontPath")) {
186
      if (NULL == (p = strchr(s, '\"')))
187
	fatalerror("%s: error locating '\"' after FontPath token\n", progName);
188
      s = ++p;
189
    } else
190
      continue;
191
192
    fpCountXF86++;
193
    p = strdup(s);
194
    if (p[strlen(p)-1] == '\n')
195
      p[strlen(p)-1] = '\0';
196
    if (p[strlen(p)-1] == '\"')
197
      p[strlen(p)-1] = '\0';
198
199
    fpListXF86 = (const char **) realloc(fpListXF86, sizeof(char *) * fpCountXF86);
200
    fpListXF86[fpCountXF86 - 1] = p;
201
  }
202
203
  fclose(f);
204
}
205
140
void writeNewConfig(void)
206
void writeNewConfig(void)
141
{
207
{
142
  FILE *f, *f1;
208
  FILE *f, *f1;
Lines 198-203 Link Here
198
  chmod(XFS_CONFIGFILE, sb.st_mode);
264
  chmod(XFS_CONFIGFILE, sb.st_mode);
199
}
265
}
200
266
267
void writeNewConfigXF86()
268
{
269
  FILE *f, *f1;
270
  char buf[250];
271
  char *s;
272
  int catFlag = 0, i;
273
  struct stat sb;
274
275
  stat(XF86_CONFIGFILE, &sb);
276
  
277
  if (NULL == (f = fopen(XF86_CONFIGFILE, "r")))
278
    fatalerror("%s: error opening %s for reading\n", progName, XF86_CONFIGFILE);
279
280
  if (NULL == (f1 = fopen(XF86_CONFIGBACKUP, "w")))
281
    fatalerror("%s: error opening %s for writing\n", progName, XF86_CONFIGBACKUP);
282
283
  while ((s = fgets(buf, sizeof(buf), f)) != NULL) {
284
    /* skip all comment lines */
285
    if (*s == '#') {
286
      fputs(s, f1);
287
      continue;
288
    }
289
290
    if (strstr(s, "FontPath") && !catFlag) {
291
      catFlag = 1;
292
      for (i = 0; i < fpCountXF86; i++) {
293
	fprintf(f1, "\tFontPath \"%s\"\n",fpListXF86[i]);
294
      }
295
    } else {
296
      if (!strstr(s, "FontPath")) {
297
	fputs(s, f1);
298
      }
299
    }
300
  }
301
302
  fclose(f);  
303
  fclose(f1);
304
  unlink(XF86_CONFIGFILE);
305
  rename(XF86_CONFIGBACKUP, XF86_CONFIGFILE);
306
  chmod(XF86_CONFIGFILE, sb.st_mode);
307
}
308
201
void addDir(const char *newDir)
309
void addDir(const char *newDir)
202
{
310
{
203
  int i, last = -1;
311
  int i, last = -1;
Lines 252-258 Link Here
252
    if (strncmp(fpList[i], fixDir, fixDirLen) == 0 &&
360
    if (strncmp(fpList[i], fixDir, fixDirLen) == 0 &&
253
	(fpList[i][fixDirLen] == '\0' ||
361
	(fpList[i][fixDirLen] == '\0' ||
254
	 strcmp(fpList[i] + fixDirLen, ":unscaled") == 0)) {
362
	 strcmp(fpList[i] + fixDirLen, ":unscaled") == 0)) {
255
	fatalerror("%s: %s already in list\n",progName, fixDir);
363
	fatalwarn("%s: %s already in list for xfs\n",progName, fixDir);
256
    }
364
    }
257
    last = i;
365
    last = i;
258
    if (!strcmp (fpList[i] + prefixLen, "misc:unscaled")) type = 0;
366
    if (!strcmp (fpList[i] + prefixLen, "misc:unscaled")) type = 0;
Lines 294-299 Link Here
294
  fpList[second] = fixDir;
402
  fpList[second] = fixDir;
295
}
403
}
296
404
405
void addDirXF86(const char *newDir)
406
{
407
  int i, last = -1;
408
  int firstType, secondType;
409
  int first = -1, second = -1;
410
  int type, prefixLen, fixDirLen;
411
  FILE *f;
412
  char *fontsdir;
413
  char *fixDir = strdup(newDir);
414
415
  fixDirLen = strlen(fixDir);
416
  if (fixDir[fixDirLen - 1] == '/') {
417
    fixDir[fixDirLen - 1] = '\0';
418
    fixDirLen--;
419
  }
420
  if (fixDirLen > 10 && !strcmp(fixDir + fixDirLen - 9, ":unscaled")) {
421
    fixDir[fixDirLen - 9] = '\0';
422
    fixDirLen -= 9;
423
  }
424
425
  if (fixDir[0] != '/')
426
    fatalerror("%s: font directories must be absolute, not adding %s\n",
427
		progName, fixDir);
428
429
  fontsdir = (char *) malloc(sizeof(char *) * (strlen(fixDir) + 12));
430
  sprintf(fontsdir, "%s/fonts.dir", fixDir);
431
  if (NULL == (f = fopen(fontsdir, "r")))
432
    fatalerror("%s: error opening %s, unwilling to add path\n",
433
		progName, fontsdir);
434
435
  fclose(f);
436
  free(fontsdir);
437
  
438
  prefixLen = strrchr(fixDir, '/') + 1 - fixDir;
439
440
  if (!strcmp (fixDir + prefixLen, "misc")) {
441
    firstType = 0;
442
    secondType = 3;
443
  } else if (!strcmp (fixDir + prefixLen, "75dpi")) {
444
    firstType = 1;
445
    secondType = 5;
446
  } else if (!strcmp (fixDir + prefixLen, "100dpi")) {
447
    firstType = 2;
448
    secondType = 6;
449
  } else {
450
    firstType = 100;
451
    secondType = 4;
452
  }  
453
454
  for (i = 0; i < fpCountXF86; i++) {
455
    if (strncmp(fpListXF86[i], fixDir, prefixLen) != 0) continue;
456
    if (strncmp(fpListXF86[i], fixDir, fixDirLen) == 0 &&
457
	(fpListXF86[i][fixDirLen] == '\0' ||
458
	 strcmp(fpListXF86[i] + fixDirLen, ":unscaled") == 0)) {
459
	fatalwarn("%s: %s already in list for XF86Config\n",progName, fixDir);
460
    }
461
    last = i;
462
    if (!strcmp (fpListXF86[i] + prefixLen, "misc:unscaled")) type = 0;
463
    else if (!strcmp (fpListXF86[i] + prefixLen, "75dpi:unscaled")) type = 1;
464
    else if (!strcmp (fpListXF86[i] + prefixLen, "100dpi:unscaled")) type = 2;
465
    else if (!strcmp (fpListXF86[i] + prefixLen, "misc")) type = 3;
466
    else if (!strcmp (fpListXF86[i] + prefixLen, "75dpi")) type = 5;
467
    else if (!strcmp (fpListXF86[i] + prefixLen, "100dpi")) type = 6;
468
    else type = 4;
469
    if (first == -1 && firstType < type)
470
      first = i;
471
    if (second == -1 && secondType < type)
472
      second = i;
473
  }
474
  if (last == -1)
475
    last = fpCountXF86;
476
  else
477
    last++;
478
  if (first == -1 && firstType < 10)
479
    first = last;
480
  if (second == -1)
481
    second = last;
482
  if (firstdir) {
483
    if (firstType < 10)
484
      first = 0;
485
    second = 0;
486
  }
487
  fpCountXF86 += (firstType < 10) ? 2 : 1;
488
  fpListXF86 = (const char **) realloc(fpListXF86, sizeof(char *) * fpCountXF86);
489
  if (firstType < 10) {
490
    char *unspecDir;
491
    memmove(fpListXF86 + first + 1, fpListXF86 + first, sizeof(char *) * (fpCountXF86 - 1 - first));
492
    unspecDir = (char *) malloc(fixDirLen + 11);
493
    sprintf(unspecDir, "%s:unscaled", fixDir);
494
    fpListXF86[first] = unspecDir;
495
    second++;
496
  }
497
  memmove(fpListXF86 + second + 1, fpListXF86 + second, sizeof(char *) * (fpCountXF86 - 1 - second));
498
  fpListXF86[second] = fixDir;
499
500
}
501
297
void removeDir(const char *delDir)
502
void removeDir(const char *delDir)
298
{
503
{
299
  int found = 0;
504
  int found = 0;
Lines 317-323 Link Here
317
    }
522
    }
318
  }
523
  }
319
  if (!found)
524
  if (!found)
320
    fatalerror("%s: %s not found in list\n",progName, newDir);
525
    fatalwarn("%s: %s not found in list for xfs\n",progName, newDir);
526
527
  free(newDir);
528
}
529
530
void removeDirXF86(const char *delDir)
531
{
532
  int found = 0;
533
  int i;
534
  char *newDir = strdup(delDir);
535
  int newDirLen;
536
537
  if (newDir[strlen(newDir)-1] == '/')
538
    newDir[strlen(newDir)-1] = '\0';
539
540
  newDirLen = strlen(newDir);
541
  for (i = 0; i < fpCountXF86; i++) {
542
    if (strncmp(fpListXF86[i], newDir, newDirLen) == 0 &&
543
	(fpListXF86[i][newDirLen] == '\0' ||
544
	 strcmp(fpListXF86[i] + newDirLen, ":unscaled") == 0)) {
545
      found = 1;
546
      if (i < fpCountXF86-1)
547
	memmove(fpListXF86 + i, fpListXF86 + i + 1, sizeof(char *) * (fpCountXF86-i-1));
548
      fpCountXF86--;
549
      i--;
550
    }
551
  }
552
  if (!found)
553
    fatalwarn("%s: %s not found in list for XF86Config\n",progName, newDir);
321
554
322
  free(newDir);
555
  free(newDir);
323
}
556
}
Lines 350-363 Link Here
350
{
583
{
351
  int i;
584
  int i;
352
  if (fpCount == 0)
585
  if (fpCount == 0)
353
    printf("No directories currently in font path.");
586
    printf("No directories currently in font path for xfs.");
354
  else {
587
  else {
355
    printf("Current directories in font path:\n");
588
    printf("Current directories in font path for xfs:\n");
356
    for (i = 0; i < fpCount; i++)
589
    for (i = 0; i < fpCount; i++)
357
      printf("%d: %s\n",i+1, fpList[i]);
590
      printf("%d: %s\n",i+1, fpList[i]);
358
  }
591
  }
359
}
592
}
360
593
594
void listPathsXF86()
595
{
596
  int i;
597
  if (fpCountXF86 == 0)
598
    printf("No directories currently in font path for XF86Config.");
599
  else {
600
    printf("Current directories in font path for XF86Config:\n");
601
    for (i = 0; i < fpCountXF86; i++)
602
      printf("%d: %s\n",i+1, fpListXF86[i]);
603
  }
604
}
605
361
int main(int argc, const char **argv)
606
int main(int argc, const char **argv)
362
{
607
{
363
  int rc, list = 0, help = 0;
608
  int rc, list = 0, help = 0;
Lines 404-423 Link Here
404
  poptFreeContext(optCon);
649
  poptFreeContext(optCon);
405
650
406
  readFontPath();
651
  readFontPath();
652
  readFontPathXF86();
407
653
408
  if (argc == 1 || list )
654
  if (argc == 1 || list ) {
409
    listPaths();
655
    listPaths();
656
    listPathsXF86();
657
  }
410
658
411
  if (newDir != NULL) {
659
  if (newDir != NULL) {
412
    addDir(newDir);
660
    addDir(newDir);
661
    addDirXF86(newDir);
413
  }
662
  }
414
663
415
  if (delDir != NULL) {
664
  if (delDir != NULL) {
416
    removeDir(delDir);
665
    removeDir(delDir);
666
    removeDirXF86(delDir);
417
  }
667
  }
418
668
419
  if (newDir != NULL || delDir != NULL) {
669
  if (newDir != NULL || delDir != NULL) {
420
    writeNewConfig();
670
    writeNewConfig();
671
    writeNewConfigXF86();
421
    restartXfs();
672
    restartXfs();
422
  }
673
  }
423
674

Return to bug 21932