mirror of
https://github.com/labwc/labwc.git
synced 2026-04-06 07:15:40 -04:00
Add scripts/helper/format-xml.c
This commit is contained in:
parent
12b6d05481
commit
af5861c611
3 changed files with 38 additions and 1 deletions
1
scripts/helper/.gitignore
vendored
1
scripts/helper/.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
find-idents
|
||||
format-xml
|
||||
*.o
|
||||
|
|
|
|||
|
|
@ -1,12 +1,17 @@
|
|||
CFLAGS += -g -Wall -O0 -std=c11
|
||||
LDFLAGS += -fsanitize=address
|
||||
|
||||
PROGS = find-idents
|
||||
PROGS = find-idents format-xml
|
||||
|
||||
all: $(PROGS)
|
||||
|
||||
find-idents: find-idents.o
|
||||
$(CC) -o $@ $^
|
||||
|
||||
format-xml: CFLAGS += `pkg-config --cflags libxml-2.0`
|
||||
format-xml: CFLAGS += `pkg-config --libs libxml-2.0`
|
||||
format-xml: format-xml.o
|
||||
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
|
||||
|
||||
clean :
|
||||
$(RM) $(PROGS) *.o
|
||||
|
|
|
|||
31
scripts/helper/format-xml.c
Normal file
31
scripts/helper/format-xml.c
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
* Helper to format XML the way libxml2 does it - because it helps stot
|
||||
* differences when working labwc-tweaks.
|
||||
*
|
||||
* Copyright (C) Johan Malm 2023
|
||||
*/
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s <filename>\n", argv[0]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
const char *filename = argv[1];
|
||||
|
||||
/* Use XML_PARSE_NOBLANKS for xmlSaveFormatFile() to indent nicely */
|
||||
xmlDoc *doc = xmlReadFile(filename, NULL, XML_PARSE_NOBLANKS);
|
||||
if (!doc) {
|
||||
fprintf(stderr, "bad file '%s'\n", filename);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
xmlSaveFormatFile(filename, doc, 1);
|
||||
xmlFreeDoc(doc);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue