Add clang-format and gitignore
This commit is contained in:
15
.clang-format
Normal file
15
.clang-format
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Tabs
|
||||||
|
UseTab: ForContinuationAndIndentation #ForIndentation
|
||||||
|
# Sized
|
||||||
|
TabWidth: 8
|
||||||
|
IndentWidth: 8
|
||||||
|
ContinuationIndentWidth: 8
|
||||||
|
|
||||||
|
# Column Limit
|
||||||
|
ColumnLimit: 80
|
||||||
|
|
||||||
|
# Functions
|
||||||
|
AllowAllArgumentsOnNextLine: false
|
||||||
|
|
||||||
|
# Allman
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
cdplayer
|
||||||
|
cdplayer.o
|
||||||
6
Makefile
6
Makefile
@@ -9,3 +9,9 @@ CFLAGS = -Itinyalsa/include
|
|||||||
|
|
||||||
$(BIN): $(OBJ)
|
$(BIN): $(OBJ)
|
||||||
$(CC) $(OBJ) -o $(BIN)
|
$(CC) $(OBJ) -o $(BIN)
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
clang-format -i cdplayer.c
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm $(BIN) $(OBJ)
|
||||||
|
|||||||
94
cdplayer.c
94
cdplayer.c
@@ -1,9 +1,9 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <linux/cdrom.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <linux/cdrom.h>
|
|
||||||
#include <tinyalsa/pcm.h>
|
#include <tinyalsa/pcm.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#define FRAMES 1
|
#define FRAMES 1
|
||||||
|
|
||||||
@@ -13,66 +13,60 @@
|
|||||||
|
|
||||||
struct cdrom_read_audio sr;
|
struct cdrom_read_audio sr;
|
||||||
|
|
||||||
void forward( int signum )
|
void forward(int signum) { sr.addr.lba += 3600; }
|
||||||
{
|
|
||||||
sr.addr.lba+=3600;
|
|
||||||
}
|
|
||||||
|
|
||||||
void backward( int signum )
|
void backward(int signum) { sr.addr.lba -= 3600; }
|
||||||
{
|
|
||||||
sr.addr.lba-=3600;
|
|
||||||
}
|
|
||||||
|
|
||||||
void weite_err( char * s )
|
void weite_err(char *s)
|
||||||
{
|
{
|
||||||
char * p;
|
char *p;
|
||||||
p=s;
|
p = s;
|
||||||
while( *p )
|
while (*p)
|
||||||
++p;
|
++p;
|
||||||
write( STDERR_FILENO, s, p-s );
|
write(STDERR_FILENO, s, p - s);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main( int argc, char * argv[] )
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fdi, card=0, device=0;
|
int fdi, card = 0, device = 0;
|
||||||
struct pcm * pcm;
|
struct pcm *pcm;
|
||||||
struct pcm_config config;
|
struct pcm_config config;
|
||||||
char *msg, buff[SIZE*FRAMES];
|
char *msg, buff[SIZE * FRAMES];
|
||||||
struct sigaction f_action, b_action;
|
struct sigaction f_action, b_action;
|
||||||
|
|
||||||
if( argc < 2 )
|
if (argc < 2)
|
||||||
{
|
{
|
||||||
weite_err( "Usage: " );
|
weite_err("Usage: ");
|
||||||
weite_err( argv[0] );
|
weite_err(argv[0]);
|
||||||
weite_err( "cdrom [card=0] [device=0]\n" );
|
weite_err("cdrom [card=0] [device=0]\n");
|
||||||
goto err0;
|
goto err0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( (fdi=open( argv[1] , O_RDONLY | O_NONBLOCK )) < 0 )
|
if ((fdi = open(argv[1], O_RDONLY | O_NONBLOCK)) < 0)
|
||||||
{
|
{
|
||||||
weite_err( "couldn't open input device " );
|
weite_err("couldn't open input device ");
|
||||||
weite_err( argv[1] );
|
weite_err(argv[1]);
|
||||||
weite_err( " \n" );
|
weite_err(" \n");
|
||||||
goto err0;
|
goto err0;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( ioctl( fdi, CDROM_DRIVE_STATUS, 0 ) )
|
switch (ioctl(fdi, CDROM_DRIVE_STATUS, 0))
|
||||||
{
|
{
|
||||||
case CDS_NO_DISC:
|
case CDS_NO_DISC:
|
||||||
weite_err( "No disk\n" );
|
weite_err("No disk\n");
|
||||||
goto err1;
|
goto err1;
|
||||||
case CDS_DRIVE_NOT_READY:
|
case CDS_DRIVE_NOT_READY:
|
||||||
weite_err( "Drive not ready\n" );
|
weite_err("Drive not ready\n");
|
||||||
goto err1;
|
goto err1;
|
||||||
case CDS_TRAY_OPEN:
|
case CDS_TRAY_OPEN:
|
||||||
weite_err( "Tray open\n" );
|
weite_err("Tray open\n");
|
||||||
goto err1;
|
goto err1;
|
||||||
case -1:
|
case -1:
|
||||||
weite_err( "Error\n" );
|
weite_err("Error\n");
|
||||||
goto err1;
|
goto err1;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( argc )
|
switch (argc)
|
||||||
{
|
{
|
||||||
case 4:
|
case 4:
|
||||||
device = *argv[3] - '0';
|
device = *argv[3] - '0';
|
||||||
@@ -82,13 +76,13 @@ int main( int argc, char * argv[] )
|
|||||||
|
|
||||||
/* Prepare signals */
|
/* Prepare signals */
|
||||||
{
|
{
|
||||||
f_action.sa_handler = forward ;
|
f_action.sa_handler = forward;
|
||||||
b_action.sa_handler = backward ;
|
b_action.sa_handler = backward;
|
||||||
|
|
||||||
sigaddset( &f_action.sa_mask, SIGUSR1 );
|
sigaddset(&f_action.sa_mask, SIGUSR1);
|
||||||
sigaddset( &b_action.sa_mask, SIGUSR2 );
|
sigaddset(&b_action.sa_mask, SIGUSR2);
|
||||||
sigaction( SIGUSR1, &f_action, NULL );
|
sigaction(SIGUSR1, &f_action, NULL);
|
||||||
sigaction( SIGUSR2, &b_action, NULL );
|
sigaction(SIGUSR2, &b_action, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* config pcm */
|
/* config pcm */
|
||||||
@@ -100,8 +94,8 @@ int main( int argc, char * argv[] )
|
|||||||
config.period_size = PERIOD;
|
config.period_size = PERIOD;
|
||||||
config.period_count = COUNT;
|
config.period_count = COUNT;
|
||||||
config.start_threshold = PERIOD;
|
config.start_threshold = PERIOD;
|
||||||
config.silence_threshold = PERIOD*COUNT;
|
config.silence_threshold = PERIOD * COUNT;
|
||||||
config.stop_threshold = PERIOD*COUNT;
|
config.stop_threshold = PERIOD * COUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* config sr */
|
/* config sr */
|
||||||
@@ -111,20 +105,20 @@ int main( int argc, char * argv[] )
|
|||||||
sr.addr_format = CDROM_LBA;
|
sr.addr_format = CDROM_LBA;
|
||||||
}
|
}
|
||||||
|
|
||||||
pcm = pcm_open( card, device, PCM_OUT , &config );
|
pcm = pcm_open(card, device, PCM_OUT, &config);
|
||||||
|
|
||||||
sr.addr.lba=0;
|
sr.addr.lba = 0;
|
||||||
while( ioctl( fdi, CDROMREADAUDIO, &sr ) != -1 )
|
while (ioctl(fdi, CDROMREADAUDIO, &sr) != -1)
|
||||||
{
|
{
|
||||||
pcm_writei( pcm, buff, SIZE*FRAMES/4 );
|
pcm_writei(pcm, buff, SIZE * FRAMES / 4);
|
||||||
sr.addr.lba+=FRAMES;
|
sr.addr.lba += FRAMES;
|
||||||
}
|
}
|
||||||
|
|
||||||
pcm_close( pcm );
|
pcm_close(pcm);
|
||||||
close( fdi );
|
close(fdi);
|
||||||
return 0;
|
return 0;
|
||||||
err1:
|
err1:
|
||||||
close( fdi );
|
close(fdi);
|
||||||
err0:
|
err0:
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user