~ubuntu-branches/ubuntu/dapper/gnats/dapper

« back to all changes in this revision

Viewing changes to gnats/pr.c

  • Committer: Bazaar Package Importer
  • Author(s): Chad Walstrom
  • Date: 2005-03-07 17:56:31 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 hoary)
  • Revision ID: james.westby@ubuntu.com-20050307175631-agtm10dvjbemuc64
Tags: 4.1.0-0
* New upstream version
* debian/rules: now uses '--with-lispdir' option instead of environment
  variable overloading. Re-enabled optimization.

Show diffs side-by-side

added added

removed removed

Lines of Context:
154
154
}
155
155
 
156
156
/* Get the PR at PATH.  PR is the PR entry to be filled in.
157
 
 
158
157
   If PRUNE is non-zero, don't read any multitext fields.  */
159
158
static int
160
159
get_pr (PR *pr, const char *path, int prune)
211
210
    }
212
211
}
213
212
 
 
213
static PR *
 
214
get_pr_from_index (const DatabaseInfo database, const char *prnum,
 
215
                   ErrorDesc *err)
 
216
{
 
217
  PR *pr = getFirstPR (database, err);
 
218
 
 
219
  /* If they gave it to us with the category, remove it. */
 
220
  if (( strrchr (prnum, '/')) != NULL)
 
221
    {
 
222
      prnum = strrchr (prnum, '/') + 1;
 
223
    }
 
224
 
 
225
  while (pr != NULL && strcmp (prnum, field_value (pr, NUMBER (database))) != 0)
 
226
    {
 
227
      pr = getNextPR (pr);
 
228
    }
 
229
 
 
230
  if (pr == NULL)
 
231
    {
 
232
      setError (err, CODE_NONEXISTENT_PR,
 
233
                "No PR %s listed in the index.", prnum);
 
234
      return NULL;
 
235
    }
 
236
 
 
237
  return pr;
 
238
}
 
239
 
214
240
/* Initializes PR for reading.  Each line of the PR should be passed
215
241
   in via addLineToPR (). */
216
242
 
1348
1374
}
1349
1375
 
1350
1376
static char *
1351
 
get_pr_path (const DatabaseInfo database,const char *prnum, ErrorDesc *err)
 
1377
get_pr_path (const DatabaseInfo database, PR *pr, const char *prnum,
 
1378
            ErrorDesc *err)
1352
1379
{
1353
1380
  char *path = NULL;
1354
1381
  const char *category = NULL;
1355
 
  PR *curr_pr_chain = getFirstPR (database, err);
1356
1382
  char *categoryFromIndex = NULL;
1357
1383
 
1358
 
  if (curr_pr_chain != NULL)
 
1384
  if (pr != NULL)
1359
1385
    {
1360
 
      PR *j;
1361
 
      for (j = curr_pr_chain ; j != NULL ; j = getNextPR (j))
1362
 
        {
1363
 
          if (strcmp (prnum, field_value (j, NUMBER (database))) == 0)
1364
 
            {
1365
 
              category = field_value (j, CATEGORY (database));
1366
 
              break;
1367
 
            }
1368
 
        }
1369
 
      if (category == NULL)
1370
 
        {
1371
 
          setError (err, CODE_NONEXISTENT_PR,
1372
 
                    "No PR %s listed in the index.", prnum);
1373
 
        }
 
1386
      category = field_value (pr, CATEGORY (database));
1374
1387
    }
1375
1388
  else
1376
1389
    {
1391
1404
}
1392
1405
 
1393
1406
int
1394
 
prExists (const DatabaseInfo database, const char *prID, ErrorDesc *err)
 
1407
prExists (const DatabaseInfo database, const char *prnum, ErrorDesc *err)
1395
1408
{
1396
 
  char *path = get_pr_path (database, prID, err);
 
1409
  PR *pr = get_pr_from_index (database, prnum, err);
 
1410
  char *path = get_pr_path (database, pr, prnum, err);
1397
1411
  int res = 0;
1398
1412
  if (path != NULL)
1399
1413
    {
1407
1421
  return res;
1408
1422
}
1409
1423
 
1410
 
char *
1411
 
lookup_pr_path (const DatabaseInfo database, const char *prnum, ErrorDesc *err)
 
1424
static bool
 
1425
pr_file_readable (const char *path, ErrorDesc *err)
1412
1426
{
1413
 
  char *path;
1414
1427
  FILE *fp;
1415
1428
 
1416
 
  /* If they gave it to us with the category, remove it. */
1417
 
  if (( strrchr (prnum, '/')) != NULL)
 
1429
  if (path == NULL)
1418
1430
    {
1419
 
      prnum = strrchr (prnum, '/') + 1;
 
1431
      return FALSE;
1420
1432
    }
1421
 
  path = get_pr_path (database, prnum, err);
1422
 
  if ((path == NULL) || ((fp = fopen (path, "r")) == NULL))
 
1433
 
 
1434
  if ((fp = fopen (path, "r")) == NULL)
1423
1435
    {
1424
 
      if (path != NULL)
1425
 
        {
1426
 
          setError (err, CODE_FILE_ERROR, "Can't open file `%s'", path);
1427
 
        }
1428
 
      return NULL;
 
1436
      setError (err, CODE_FILE_ERROR, "Can't open file `%s'", path);
 
1437
      return FALSE;
1429
1438
    }
1430
1439
 
1431
1440
  fclose (fp);
1432
 
  return path;
 
1441
  return TRUE;
1433
1442
}
1434
1443
 
1435
1444
PR *
1436
 
readPRWithNum (const DatabaseInfo database, const char *prID,
 
1445
readPRWithNum (const DatabaseInfo database, const char *prnum,
1437
1446
               int prune, ErrorDesc *err)
1438
1447
{
1439
1448
  PR *pr = NULL;
1440
 
  char *path = lookup_pr_path (database, prID, err);
 
1449
  PR *index_pr = get_pr_from_index (database, prnum, err);
 
1450
  char *path = get_pr_path (database, index_pr, prnum, err);
1441
1451
 
1442
1452
  if (path != NULL)
1443
1453
    {
1444
 
      pr = allocPR (database);
1445
 
      if (get_pr (pr, path, prune) == 0)
 
1454
      if (pr_file_readable (path, err))
 
1455
        {
 
1456
          pr = allocPR (database);
 
1457
          setPrevPR (pr, getPrevPR (index_pr));
 
1458
          setNextPR (pr, getNextPR (index_pr));
 
1459
          if (get_pr (pr, path, prune) == 0)
 
1460
            {
 
1461
              free_pr (pr);
 
1462
              pr = NULL;
 
1463
            }
 
1464
        }
 
1465
      free (path);
 
1466
    }
 
1467
  return pr;
 
1468
}
 
1469
 
 
1470
int
 
1471
pr_delete (const DatabaseInfo database, const char *prnum, ErrorDesc *err)
 
1472
{
 
1473
  PR *pr;
 
1474
  char *path = NULL;
 
1475
 
 
1476
  pr = get_pr_from_index (database, prnum, err);
 
1477
  path = get_pr_path (database, pr, prnum, err);
 
1478
 
 
1479
  if (path == NULL || !pr_file_readable (path, err))
 
1480
    {
 
1481
      if (path != NULL)
1446
1482
        {
1447
 
          free_pr (pr);
1448
 
          pr = NULL;
 
1483
          free (path);
1449
1484
        }
1450
 
    }
1451
 
  return pr;
 
1485
      return -1;
 
1486
    }
 
1487
 
 
1488
  if (removePRFromIndex (database, prnum, err))
 
1489
    {
 
1490
      free (path);
 
1491
      return -5;
 
1492
    }
 
1493
  
 
1494
  if (unlink (path))
 
1495
    {
 
1496
      setError (err, CODE_FILE_ERROR, "Unable to unlink file %s\n", path);
 
1497
      free (path);
 
1498
      return -6;
 
1499
    }
 
1500
 
 
1501
  free (path);
 
1502
  return 1;
1452
1503
}
1453
1504
 
1454
1505
void