Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## main.c
- #include <stdlib.h>
- #include <unistd.h>
- #include <getopt.h>
- #include "main.h"
- #include "list.h"
- int objectx_abi = 1; /* Object X ABI ver */
- char *ox_app_name = "elf32.dlm.so"; /* Application Name */
- char *ox_app_auth = "The Object X Group"; /* Application Author */
- void show_version() {
- fprintf(stdout, "%s version %d.%d%d\n", APP_NAME, APP_VER_MAJOR,
- APP_VER_MINOR_1, APP_VER_MINOR_2);
- return;
- }
- void show_usage() {
- fprintf(stdout,
- "%s- %s\n"
- "version %d.%d%d\n"
- "Usage: %s [options] rc_file\n"
- "\n"
- "Options: \n"
- " -f, --temp-file Specify the temporary file %s will create.\n"
- " -v, --version Displays %s version information. \n"
- " -h, --help Displays this message. \n"
- " \n"
- " \n"
- " %s is a part of the Object X compiler suite, created by Robert Butler. \n"
- " \n"
- " DISCLAIMER- \n"
- " The Object X compiler suite is partially based from the GNU C Compiler \n"
- " Suite. This compiler suite is currently maintained by Robert M. Butler.\n"
- " Please email bug reports to the Object X build team <build@objectx.org>\n"
- " \n",
- APP_NAME, APP_DESC, APP_VER_MAJOR, APP_VER_MINOR_1, APP_VER_MINOR_2,APP_NAME,
- APP_NAME, APP_NAME, APP_NAME );
- return;
- }
- int main( int argc, char *argv[] ) {
- FILE *handle;
- static char *rc_file, *tmp_file;
- int opt, option, arg_count;
- static struct option long_options[] = {
- /* Name argument flag value */
- { "help", no_argument, NULL, 'h' },
- { "temp-file", required_argument, &tmp_file, 'f' },
- { "version", no_argument, NULL, 'v' },
- { 0, 0, 0, 0 }
- };
- while ((opt = getopt_long( argc, argv, "hvf:o:012",
- long_options,&option)) != -1) {
- switch (opt) {
- case 'h':
- show_usage();
- return 0;
- break;
- case 'v':
- show_version();
- return 0;
- break;
- case 'f':
- fprintf(stdout, "%s[%d]: %s\n", __FILE__,__LINE__-1,rc_file);
- break;
- case '?':
- show_usage();
- return 0;
- break;
- case ':':
- fprintf(stdout, "%s[%d]: Option `%c' is missing a value.\n",
- __FILE__, __LINE__, opt);
- show_usage();
- return 0;
- break;
- }
- }
- fprintf(stdout, "%s[%d]: %s\n", __FILE__,__LINE__-1,rc_file);
- fprintf(stdout, "%s[%d]: Resource script filename: %s \n",
- __FILE__, __LINE__, argv[ argc-1 ]);
- struct version e_version[] = {
- { "Application Name", ox_app_name, sizeof( ox_app_name ) },
- { "Application Vendor",ox_app_auth, sizeof( ox_app_auth ) },
- { "Object X Version", &objectx_abi, sizeof( objectx_abi ) },
- { NULL, NULL, 0 }
- };
- if ((handle=file_open(argv[argc-1]))==FALSE) {
- printf("%s[%d]: Failed to open %s.\n",
- __FILE__, __LINE__-1, argv[1] );
- return -1;
- }
- int x; struct verList *list, *head, *lp;
- for (x=0; e_version[x].e_name != NULL; x++) {
- if (x < 1) {
- head = list_create(e_version[0]);
- list = head;
- }
- else {
- list = listItem_add(list, e_version[x]);
- }
- }
- lp = head;
- while (lp != NULL)
- {
- if (do_serialize(handle, lp) != 0)
- {
- // Abort, abort, abort!
- break;
- }
- }
- fclose( handle );
- }
- ## main.h
- #ifndef _OBJECTX_MAIN
- #define _OBJECTX_MAIN
- #include <fcntl.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <linux/errno.h>
- #include <error.h>
- int errno;
- #define FALSE -1
- #define TRUE 0
- #define BOOL int
- #define APP_NAME "rvc"
- #define APP_DESC "The Object X resource version compile and linker"
- #define APP_VER_MAJOR 1
- #define APP_VER_MINOR_1 0
- #define APP_VER_MINOR_2 0
- struct version {
- char *e_name;
- void *e_data;
- unsigned int e_size;
- };
- #endif // _OBJECTX_MAIN
- ## type.h
- #ifndef _TYPE_H
- #define _TYPE_H
- #define FALSE -1
- #define TRUE 0
- #define BOOL int
- #endif // _TYPE_H
- ## file.c
- #include "main.h"
- #include "list.h"
- #include "type.h"
- BOOL file_write(FILE *handle, struct verList *root, int size)
- {
- // Write our records
- struct verList *list;
- list = root;
- while (list != 0) {
- struct version *cur_record = (struct version*)list->e_data;
- do_serialize(handle, cur_record);
- list = list->next;
- }
- }
- FILE *file_open(char *path)
- {
- // Open our file
- FILE *handle;
- if (0 == (handle=fopen(path, "wb+")))
- {
- printf("%s[%d]: Failed to open %s.\n", __FILE__, __LINE__-1, APP_NAME );
- return -1;
- }
- return handle;
- }
- ## list.c
- #include "main.h"
- #include "list.h"
- #include "type.h"
- int do_serialize(FILE *handle, struct verList **segment) {
- if ( NULL == segment )
- return -1;
- if ( NULL == (*segment)->e_name )
- return -1;
- if ( NULL == (*segment)->e_data )
- return -1;
- if ( NULL == (*segment)->e_size )
- return -1;
- char *name = (*segment)->e_name;
- char *value = (*segment)->e_data;
- int *e_tmp = (*segment)->e_size;
- char *d_tmp = value;
- char *s_tmp = name;
- int val_len= 0, str_len= 0;
- while ( *d_tmp++ != '\0') val_len++;
- while ( *s_tmp++ != '\0') str_len++;
- int ret;
- if (ret = (fwrite(name, str_len, 1, handle)) != 1)
- return -1;
- if (ret = (fwrite(value, val_len, 1, handle)) != 1)
- return -1;
- if (ret = (fwrite(e_tmp,sizeof(int),1,handle)) != 1)
- return -1;
- segment = segment->next;
- return 0;
- }
- struct verList* list_create(void *data) {
- struct verList *root = (struct verList*)malloc( sizeof( struct verList ));
- root->next= 0;
- root->e_data= data;
- return root;
- }
- void list_destroy(struct verList* root) {
- struct verList *cur = root;
- struct verList *list = root;
- while (cur != 0) {
- list = cur;
- cur = cur->next;
- free(list);
- list = 0;
- }
- }
- struct verList* listItem_add(struct verList *list, void *data) {
- if (0 == list)
- return 0;
- struct verList *listItem = (struct verList*)malloc(sizeof(struct verList));
- list->next = listItem;
- listItem->next = 0;
- listItem->e_data = data;
- //listItem->e_size = Before->e_size;
- return listItem;
- }
- struct verList* listItem_Insert(struct verList *list, void *data) {
- if (0 == list)
- return 0;
- struct verList *listItem = (struct verList*)malloc(sizeof(struct verList));
- listItem->e_data = data;
- listItem->next = list->next;
- list->next = listItem;
- return listItem;
- }
- ## list.h
- #ifndef _LIST_H
- #define _LIST_H
- struct verList {
- struct verList *next;
- char *e_name;
- void *e_data;
- unsigned int e_size;
- };
- /* Methods */
- struct verList *create_version_table( void *list );
- void destroy_version_table( struct verLIst *root );
- struct verList *do_version_insert( struct verList *list, void *e_data );
- struct verList *do_version_create( struct verList *list, void *e_data );
- #endif // _LIST_H
Add Comment
Please, Sign In to add comment