Help making manipulable variable


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Help making manipulable variable
# 1  
Old 01-10-2013
Help making manipulable variable

Hello, I'm a newbie in C, but i'm trying to make a file to configurate/manipulate variables of a C code.

I tried using int and extern int throught a header or another C code but it doesn't seems to work (even throught the makefile). I also tried (with XML) to put a data structure to hold the shared variables with the XML_SetUserData function to pass a pointer to this structure to the handlers.

Maybe i did something wrong, but i can't find where. Any help is welcome. Thanks.

---------- Post updated at 04:46 PM ---------- Previous update was at 03:41 PM ----------

So,here is code.h

Code:
#ifndef _CODE_H
#define _CODE_H
#include <stdio.h>
#include <stdlib.h>

#define X 1
typedef unsigned char X_Bool;
#define X_TRUE ((X_Bool) 1)
#define X_FALSE ((X_Bool) 0)
#define X_MODE ((X_Bool) 2)
#endif


then conf.c

Code:
int M;
M = 2;


and then code.c

Code:
#include <stdio.h>
#include "code.h"
extern int X;
extern int M;
int main(int argc, char *argv[]) {
while (1) {
printf("\n%s\n", M);
printf("\n%s\n", X);
printf("\n%s\n", X_MODE);
}


and then the compile
Code:
gcc code.c conf.c -o decode `pkg-config --cflags --libs gstreamer-0.10

I want to change variable throught code.h or conf.c for code.c but it fail. It seems to ignore it with no errors.
# 2  
Old 01-10-2013
The code you've given won't compile, missing brackets in places.

I don't know what your while-loop is for. That will just print the same things over and over.

The variable X won't work right, because X also exists as a #define, whenever you use X it will be turned into 1 by simple text replacement.

The variable M ought to properly show up as 2. What were you expecting it to do, and in what way was it not working?
# 3  
Old 01-10-2013
problem

I'm using Gstreamer, and i want to have the possibility to change parameters in my pipeline throught a configuration file.

Here is my pipeline:

Code:
str = g_strdup_printf (
   "rtspsrc protocols=PTCP latency=LAT "
   " timeout=TIMO  buffer-mode=BUFM location=%s name=src"
   " ! queue ! gstrtpbin latency=LATE name=srcbin "
   " ! queue min-threshold-time=QUE ! rtph264depay ! ffdec_h264"
   " ! interlace top-field-first=true field-pattern=FP"
   " ! videoscale add-borders=true ! videorate"
   " ! colorspace"
   " ! video/x-raw-yuv,framerate=25/1,height=576,width=720,format=(fourcc)UYVY"
   " ! decklinksink name=sink mode= mood "
   " src. ! queue min-threshold-time=QMTT ! rtpmp4adepay !  aacparse ! faad ! audioconvert ! audioresample ! sink. sync=true"
   ,argv[1]);
pipeline = gst_parse_launch (str,NULL);

which i want to be able change PTCP, LAT, TIMO, BUFM, LATE, QUE, FP, mood, and the caps
# 4  
Old 01-10-2013
An .h file is not a configuration file. It gets read when you run gcc, not when you run the program.

You could have a simple configuration file like this:

Code:
VAR1=VALUE1
VAR2=VALUE2
...

and use it like this:

Code:
char buf[512], var[512], val[512];
FILE *fp=fopen("/path/to/configfile", "r");

setenv("protocols", "PCTP"); // Set a default

while(fgets(buf, 512, fp) != NULL)
{
        if(sscanf(buf, "%[^=]=%s", var, val) != 2) continue;
        setenv(var, val);
}
fclose(fp);

str = g_strdup_printf (
   "rtspsrc protocols=%s latency=LAT "
   " timeout=TIMO  buffer-mode=BUFM location=%s name=src"
   " ! queue ! gstrtpbin latency=LATE name=srcbin "
   " ! queue min-threshold-time=QUE ! rtph264depay ! ffdec_h264"
   " ! interlace top-field-first=true field-pattern=FP"
   " ! videoscale add-borders=true ! videorate"
   " ! colorspace"
   " ! video/x-raw-yuv,framerate=25/1,height=576,width=720,format=(fourcc)UYVY"
   " ! decklinksink name=sink mode= mood "
   " src. ! queue min-threshold-time=QMTT ! rtpmp4adepay !  aacparse ! faad ! audioconvert ! audioresample ! sink. sync=true"
   ,getenv("protocols"), argv[1]);

# 5  
Old 01-10-2013
Thank you Corona ! I've got things to do, but i'll do it as soon as possible.

I have now done the code, and it work. Thanks again Smilie

Last edited by Weavel37; 01-11-2013 at 09:35 AM..
This User Gave Thanks to Weavel37 For This Post:
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help with making the output of a command a variable

I'm writing a script that goes something like this: #!/bin/bash zenity --list --checklist --title="Choose Packages to Install" --width="1000" --height="400" \ --column="Select" --column="Package Name" --column="Description" \ GIMP=$( " " GIMP "GIMP is a free and open source photo editor." ... (1 Reply)
Discussion started by: Defunct_Lizard
1 Replies

2. UNIX for Beginners Questions & Answers

Help me making this script

This script is executed whenever a new vehicle is added to the cycle-motor park of campus. The script asks for the following information about the car and adds a new line to the vehicle file.txt: name (name of an animal, unique identifier), color, mark, model, type (e.g., electrical, manual),... (2 Replies)
Discussion started by: andre2222
2 Replies

3. UNIX for Advanced & Expert Users

Regarding help for making own OS

Dear Fellow, I want to make my own OS, Kindly suggest from where i should start. please help me out. (2 Replies)
Discussion started by: zaigham_tt
2 Replies

4. UNIX for Dummies Questions & Answers

Making a function

I am practicing making my own functions in bash for an upcoming exam. For this example, I want to print out a message and maybe add two numbers. What I would do then is: bash-3.2$ function practice { #code to print #code to add } This would be run using an input file, that would... (1 Reply)
Discussion started by: Midwest Product
1 Replies

5. Shell Programming and Scripting

Making script show command (e.g. copy) being executed and variable substitution?

When script is running you only see when some of the commands are not successfull. Is there a way to see which command are executed and to show the substitution of variables as every line is executed ? (3 Replies)
Discussion started by: gr0124
3 Replies

6. Shell Programming and Scripting

How to define a variable with variable definition is stored in a variable?

Hi all, I have a variable say var1 (output from somewhere, which I can't change)which store something like this: echo $var1 name=fred age=25 address="123 abc" password=pass1234 how can I make the variable $name, $age, $address and $password contain the info? I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies

7. UNIX for Dummies Questions & Answers

making a variable as string

I am evaluating a variable from a database and storing it as inside. The value of the variable is alpha numeric.How can i make this a string type.Any functions for the same. (1 Reply)
Discussion started by: dr46014
1 Replies

8. Shell Programming and Scripting

Making a Directory

Hi everyone, Im trying to make a new directory based on a name given in a file called directory_file which contains the following content: garbage gargbage Directory: running more garbage gargbage more garbage gargbage more garbage gargbage So basically i have a shell script that... (3 Replies)
Discussion started by: nbvcxzdz
3 Replies

9. UNIX for Dummies Questions & Answers

Making a variable equal a pattern

Hi, I would like to assign a pattern to a variable eg test8* or abc etc The problem I have is that when I assign the pattern to the variable, if any files within the current directory match the pattern then the variable will be evaluated to equal the filenames rather than the literal pattern.... (3 Replies)
Discussion started by: Bab00shka
3 Replies
Login or Register to Ask a Question