MCPcopy Create free account
hub / github.com/coreutils/coreutils / abmon_init

Function abmon_init

src/ls.c:1336–1380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1334 Return true if successful. */
1335
1336static bool
1337abmon_init (char abmon[12][ABFORMAT_SIZE])
1338{
1339#ifndef HAVE_NL_LANGINFO
1340 return false;
1341#else
1342 int max_mon_width = 0;
1343 int mon_width[12];
1344 int mon_len[12];
1345
1346 for (int i = 0; i < 12; i++)
1347 {
1348 char const *abbr = nl_langinfo (ABMON_1 + i);
1349 mon_len[i] = strnlen (abbr, ABFORMAT_SIZE);
1350 if (mon_len[i] == ABFORMAT_SIZE)
1351 return false;
1352 if (strchr (abbr, '%'))
1353 return false;
1354 mon_width[i] = mbswidth (strcpy (abmon[i], abbr), MBSWIDTH_FLAGS);
1355 if (mon_width[i] < 0)
1356 return false;
1357 max_mon_width = MAX (max_mon_width, mon_width[i]);
1358 }
1359
1360 for (int i = 0; i < 12; i++)
1361 {
1362 int fill = max_mon_width - mon_width[i];
1363 if (ABFORMAT_SIZE - mon_len[i] <= fill)
1364 return false;
1365 bool align_left = !c_isdigit (abmon[i][0]);
1366 int fill_offset;
1367 if (align_left)
1368 fill_offset = mon_len[i];
1369 else
1370 {
1371 memmove (abmon[i] + fill, abmon[i], mon_len[i]);
1372 fill_offset = 0;
1373 }
1374 memset (abmon[i] + fill_offset, ' ', fill);
1375 abmon[i][mon_len[i] + fill] = '\0';
1376 }
1377
1378 return true;
1379#endif
1380}
1381
1382/* Initialize ABFORMAT and USE_ABFORMAT. */
1383

Callers 1

abformat_initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected